[llvm] Reland #2 - [Offload] Introduce offload-tblgen and initial new API implementation (#108413. #117704) (PR #117894)
Callum Fare via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 27 06:57:55 PST 2024
https://github.com/callumfare created https://github.com/llvm/llvm-project/pull/117894
Relands #117704, which relanded changes from #108413 - this was reverted due to build issues. The new offload library did not build with `LIBOMPTARGET_OMPT_SUPPORT` enabled, which was not picked up by pre-merge testing.
The last commit contains the fix; everything else is otherwise identical to the approved PR.
___
### New API
Previous discussions at the LLVM/Offload meeting have brought up the need for a new API for exposing the functionality of the plugins. This change introduces a very small subset of a new API, which is primarily for testing the offload tooling and demonstrating how a new API can fit into the existing code base without being too disruptive. Exact designs for these entry points and future additions can be worked out over time.
The new API does however introduce the bare minimum functionality to implement device discovery for Unified Runtime and SYCL. This means that the `urinfo` and `sycl-ls` tools can be used on top of Offload. A (rough) implementation of a Unified Runtime adapter (aka plugin) for Offload is available [here](https://github.com/callumfare/unified-runtime/tree/offload_adapter). Our intention is to maintain this and use it to implement and test Offload API changes with SYCL.
### Demoing the new API
```sh
# From the runtime build directory
$ ninja LibomptUnitTests
$ OFFLOAD_TRACE=1 ./offload/unittests/OffloadAPI/offload.unittests
```
### Open questions and future work
* Only some of the available device info is exposed, and not all the possible device queries needed for SYCL are implemented by the plugins. A sensible next step would be to refactor and extend the existing device info queries in the plugins. The existing info queries are all strings, but the new API introduces the ability to return any arbitrary type.
* It may be sensible at some point for the plugins to implement the new API directly, and the higher level code on top of it could be made generic, but this is more of a long-term possibility.
>From c9caae9425294ca21720b3dba5c2649fa18d697a 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/24] [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 dfd25bad608436..27c9de509c436e 100644
--- a/offload/CMakeLists.txt
+++ b/offload/CMakeLists.txt
@@ -351,6 +351,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 acceb9a49fa895982675651e4cf0390f41c0125a 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/24] 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 5dc6c77091c377d4826db2e82c5e994620bcfd30 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/24] 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 2addaeb914565944f2f0c0bf13829e701c24cc2f 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/24] 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 51e1b35909222523c9a4db7a8052e83e602a0d3c 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/24] 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 b948bfb2f49fc7abab80e5ff7ff5d6795db0cc0b 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/24] 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 69fc42d1be73e3884a4fc424264f70831c1060f0 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/24] 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 2f3f090f908693f88f2379b44fad6a29208e40c1 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/24] 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 52015ecea1281771071407cb9ff2ca756ed2eadf 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/24] 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 9d7343b2becf017726f19db4cab86aa1440c6104 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/24] 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 b88bd00790d57d30c58013ff0354abf28eee4ec4 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/24] 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 ad359d77a6def6ac1bfe6b3d857042352a9bb369 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/24] 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 11508b04b3ee1b63452d95995fb345398eafe37b 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/24] 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 f78b0d5fd2625916f7321e21ca0c644ca10e161b 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/24] 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()) {
>From 358e0c520b75977dbd4d7ef853621d2067cd43e6 Mon Sep 17 00:00:00 2001
From: Callum Fare <callum at codeplay.com>
Date: Fri, 25 Oct 2024 17:31:48 +0100
Subject: [PATCH 15/24] Add offload-tblgen tests
---
offload/cmake/OpenMPTesting.cmake | 12 ++++++
offload/new-api/include/offload_exports | 10 +++++
offload/new-api/include/offload_funcs.inc | 10 +++++
offload/new-api/include/offload_print.hpp | 39 +++++++++---------
offload/test/lit.cfg | 3 +-
offload/test/lit.site.cfg.in | 1 +
.../tools/offload-tblgen/default_returns.td | 40 +++++++++++++++++++
.../test/tools/offload-tblgen/entry_points.td | 37 +++++++++++++++++
.../tools/offload-tblgen/functions_basic.td | 39 ++++++++++++++++++
.../offload-tblgen/functions_code_loc.td | 26 ++++++++++++
.../test/tools/offload-tblgen/print_enum.td | 34 ++++++++++++++++
.../tools/offload-tblgen/print_function.td | 38 ++++++++++++++++++
.../tools/offload-tblgen/EntryPointGen.cpp | 2 +-
offload/tools/offload-tblgen/FuncsGen.cpp | 7 ++++
offload/tools/offload-tblgen/PrintGen.cpp | 2 +-
15 files changed, 276 insertions(+), 24 deletions(-)
create mode 100644 offload/test/tools/offload-tblgen/default_returns.td
create mode 100644 offload/test/tools/offload-tblgen/entry_points.td
create mode 100644 offload/test/tools/offload-tblgen/functions_basic.td
create mode 100644 offload/test/tools/offload-tblgen/functions_code_loc.td
create mode 100644 offload/test/tools/offload-tblgen/print_enum.td
create mode 100644 offload/test/tools/offload-tblgen/print_function.td
diff --git a/offload/cmake/OpenMPTesting.cmake b/offload/cmake/OpenMPTesting.cmake
index 6609d6301d0f93..f97def2c52eba9 100644
--- a/offload/cmake/OpenMPTesting.cmake
+++ b/offload/cmake/OpenMPTesting.cmake
@@ -48,6 +48,17 @@ function(find_standalone_test_dependencies)
return()
endif()
+ find_program(OFFLOAD_TBLGEN_EXECUTABLE
+ NAMES offload-tblgen
+ PATHS ${OPENMP_LLVM_TOOLS_DIR})
+ if (NOT OFFLOAD_TBLGEN_EXECUTABLE)
+ message(STATUS "Cannot find 'offload-tblgen'.")
+ message(STATUS "Please put 'not' in your PATH, set OFFLOAD_TBLGEN_EXECUTABLE to its full path, or point OPENMP_LLVM_TOOLS_DIR to its directory.")
+ message(WARNING "The check targets will not be available!")
+ set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE)
+ return()
+ endif()
+
find_program(OPENMP_NOT_EXECUTABLE
NAMES not
PATHS ${OPENMP_LLVM_TOOLS_DIR})
@@ -82,6 +93,7 @@ else()
set(OPENMP_FILECHECK_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/FileCheck)
endif()
set(OPENMP_NOT_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/not)
+ set(OFFLOAD_TBLGEN_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/offload-tblgen)
set(OFFLOAD_DEVICE_INFO_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-offload-device-info)
endif()
diff --git a/offload/new-api/include/offload_exports b/offload/new-api/include/offload_exports
index 3a2e9adf1340c6..1940eeed720df6 100644
--- a/offload/new-api/include/offload_exports
+++ b/offload/new-api/include/offload_exports
@@ -10,6 +10,16 @@ global:
offloadDeviceGet;
offloadDeviceGetInfo;
offloadDeviceGetInfoSize;
+ offloadInitWithCodeLoc;
+ offloadShutDownWithCodeLoc;
+ offloadPlatformGetWithCodeLoc;
+ offloadPlatformGetCountWithCodeLoc;
+ offloadPlatformGetInfoWithCodeLoc;
+ offloadPlatformGetInfoSizeWithCodeLoc;
+ offloadDeviceGetCountWithCodeLoc;
+ offloadDeviceGetWithCodeLoc;
+ offloadDeviceGetInfoWithCodeLoc;
+ offloadDeviceGetInfoSizeWithCodeLoc;
local:
*;
};
diff --git a/offload/new-api/include/offload_funcs.inc b/offload/new-api/include/offload_funcs.inc
index 2b062b9f69cb4e..afa4c11e46977a 100644
--- a/offload/new-api/include/offload_funcs.inc
+++ b/offload/new-api/include/offload_funcs.inc
@@ -20,5 +20,15 @@ OFFLOAD_FUNC(offloadDeviceGetCount)
OFFLOAD_FUNC(offloadDeviceGet)
OFFLOAD_FUNC(offloadDeviceGetInfo)
OFFLOAD_FUNC(offloadDeviceGetInfoSize)
+OFFLOAD_FUNC(offloadInitWithCodeLoc)
+OFFLOAD_FUNC(offloadShutDownWithCodeLoc)
+OFFLOAD_FUNC(offloadPlatformGetWithCodeLoc)
+OFFLOAD_FUNC(offloadPlatformGetCountWithCodeLoc)
+OFFLOAD_FUNC(offloadPlatformGetInfoWithCodeLoc)
+OFFLOAD_FUNC(offloadPlatformGetInfoSizeWithCodeLoc)
+OFFLOAD_FUNC(offloadDeviceGetCountWithCodeLoc)
+OFFLOAD_FUNC(offloadDeviceGetWithCodeLoc)
+OFFLOAD_FUNC(offloadDeviceGetInfoWithCodeLoc)
+OFFLOAD_FUNC(offloadDeviceGetInfoSizeWithCodeLoc)
#undef OFFLOAD_FUNC
diff --git a/offload/new-api/include/offload_print.hpp b/offload/new-api/include/offload_print.hpp
index 36c4bed2b14669..d94a62b967ae69 100644
--- a/offload/new-api/include/offload_print.hpp
+++ b/offload/new-api/include/offload_print.hpp
@@ -290,9 +290,9 @@ inline std::ostream &operator<<(std::ostream &os,
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,
+ const struct offload_platform_get_params_t *params) {
os << ".NumEntries = ";
os << *params->pNumEntries;
os << ", ";
@@ -308,17 +308,17 @@ inline std::ostream &operator<<(
return os;
}
-inline std::ostream &operator<<(
- std::ostream &os,
- [[maybe_unused]] const struct offload_platform_get_count_params_t *params) {
+inline std::ostream &
+operator<<(std::ostream &os,
+ const struct offload_platform_get_count_params_t *params) {
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) {
+inline std::ostream &
+operator<<(std::ostream &os,
+ const struct offload_platform_get_info_params_t *params) {
os << ".Platform = ";
printPtr(os, *params->pPlatform);
os << ", ";
@@ -335,8 +335,7 @@ inline std::ostream &operator<<(
inline std::ostream &
operator<<(std::ostream &os,
- [[maybe_unused]] const struct offload_platform_get_info_size_params_t
- *params) {
+ const struct offload_platform_get_info_size_params_t *params) {
os << ".Platform = ";
printPtr(os, *params->pPlatform);
os << ", ";
@@ -348,9 +347,9 @@ operator<<(std::ostream &os,
return os;
}
-inline std::ostream &operator<<(
- std::ostream &os,
- [[maybe_unused]] const struct offload_device_get_count_params_t *params) {
+inline std::ostream &
+operator<<(std::ostream &os,
+ const struct offload_device_get_count_params_t *params) {
os << ".Platform = ";
printPtr(os, *params->pPlatform);
os << ", ";
@@ -360,8 +359,7 @@ inline std::ostream &operator<<(
}
inline std::ostream &
-operator<<(std::ostream &os,
- [[maybe_unused]] const struct offload_device_get_params_t *params) {
+operator<<(std::ostream &os, const struct offload_device_get_params_t *params) {
os << ".Platform = ";
printPtr(os, *params->pPlatform);
os << ", ";
@@ -380,9 +378,9 @@ operator<<(std::ostream &os,
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,
+ const struct offload_device_get_info_params_t *params) {
os << ".Device = ";
printPtr(os, *params->pDevice);
os << ", ";
@@ -399,8 +397,7 @@ inline std::ostream &operator<<(
inline std::ostream &
operator<<(std::ostream &os,
- [[maybe_unused]] const struct offload_device_get_info_size_params_t
- *params) {
+ const struct offload_device_get_info_size_params_t *params) {
os << ".Device = ";
printPtr(os, *params->pDevice);
os << ", ";
diff --git a/offload/test/lit.cfg b/offload/test/lit.cfg
index 2f1ef3e98d8172..658ae5f9653ba9 100644
--- a/offload/test/lit.cfg
+++ b/offload/test/lit.cfg
@@ -66,7 +66,7 @@ def evaluate_bool_env(env):
config.name = 'libomptarget :: ' + config.libomptarget_current_target
# suffixes: A list of file extensions to treat as test files.
-config.suffixes = ['.c', '.cpp', '.cc', '.f90', '.cu']
+config.suffixes = ['.c', '.cpp', '.cc', '.f90', '.cu', '.td']
# excludes: A list of directories to exclude from the testuites.
config.excludes = ['Inputs']
@@ -418,3 +418,4 @@ config.substitutions.append(("%flags", config.test_flags))
config.substitutions.append(("%not", config.libomptarget_not))
config.substitutions.append(("%offload-device-info",
config.offload_device_info))
+config.substitutions.append(("%offload-tblgen", config.offload_tblgen))
diff --git a/offload/test/lit.site.cfg.in b/offload/test/lit.site.cfg.in
index a1cb5acc38a405..ce3f6abf50a132 100644
--- a/offload/test/lit.site.cfg.in
+++ b/offload/test/lit.site.cfg.in
@@ -28,5 +28,6 @@ config.libomptarget_debug = @LIBOMPTARGET_DEBUG@
config.has_libomptarget_ompt = @LIBOMPTARGET_OMPT_SUPPORT@
config.libomptarget_has_libc = @LIBOMPTARGET_GPU_LIBC_SUPPORT@
config.libomptarget_test_pgo = @LIBOMPTARGET_TEST_GPU_PGO@
+config.offload_tblgen = "@OFFLOAD_TBLGEN_EXECUTABLE@"
# Let the main config do the real work.
lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg")
diff --git a/offload/test/tools/offload-tblgen/default_returns.td b/offload/test/tools/offload-tblgen/default_returns.td
new file mode 100644
index 00000000000000..432063e0174afa
--- /dev/null
+++ b/offload/test/tools/offload-tblgen/default_returns.td
@@ -0,0 +1,40 @@
+// RUN: %offload-tblgen -gen-api -I %S/../../../new-api/API %s | %fcheck-generic --check-prefix=CHECK-API
+// RUN: %offload-tblgen -gen-entry-points -I %S/../../../new-api/API %s | %fcheck-generic --check-prefix=CHECK-VALIDATION
+
+// Check implicit returns are included in documentation and the validation
+// wrappers where applicable
+
+include "APIDefs.td"
+
+def : Handle {
+ let name = "offload_foo_handle_t";
+ let desc = "Example handle type";
+}
+
+def : Function {
+ let name = "FunctionA";
+ let desc = "Function A description";
+ let details = [ "Function A detailed information" ];
+ let params = [
+ Param<"uint32_t", "ParamValue", "A plain value parameter">,
+ Param<"offload_foo_handle_t", "ParamHandle", "A handle parameter">,
+ Param<"uint32_t*", "ParamPointer", "A pointer parameter">,
+ Param<"uint32_t*", "ParamPointerOpt", "An optional pointer parameter", PARAM_OUT_OPTIONAL>
+ ];
+ let returns = [];
+}
+
+// CHECK-API: /// @returns
+// CHECK-API: OFFLOAD_RESULT_SUCCESS
+// CHECK-API: OFFLOAD_ERRC_INVALID_NULL_HANDLE
+// CHECK-API-NEXT: `NULL == ParamHandle`
+// CHECK-API: OFFLOAD_ERRC_INVALID_NULL_POINTER
+// CHECK-API-NEXT: `NULL == ParamPointer`
+// CHECK-API-NOT: `NULL == ParamPointerOpt`
+
+// CHECK-VALIDATION: FunctionA_val
+// CHECK-VALIDATION: if (NULL == ParamHandle)
+// CHECK-VALIDATION-NEXT: return OFFLOAD_ERRC_INVALID_NULL_HANDLE;
+// CHECK-VALIDATION: if (NULL == ParamPointer)
+// CHECK-VALIDATION-NEXT: return OFFLOAD_ERRC_INVALID_NULL_POINTER;
+// CHECK-VALIDATION-NOT: if (NULL == ParamPointerOpt)
diff --git a/offload/test/tools/offload-tblgen/entry_points.td b/offload/test/tools/offload-tblgen/entry_points.td
new file mode 100644
index 00000000000000..2d2bd1f5e3bfcc
--- /dev/null
+++ b/offload/test/tools/offload-tblgen/entry_points.td
@@ -0,0 +1,37 @@
+// RUN: %offload-tblgen -gen-entry-points -I %S/../../../new-api/API %s | %fcheck-generic
+
+// Check entry point wrapper functions are generated correctly
+
+include "APIDefs.td"
+
+def : Function {
+ let name = "FunctionA";
+ let desc = "Function A description";
+ let details = [ "Function A detailed information" ];
+ let params = [
+ Param<"uint32_t", "ParamA", "Parameter A description">,
+ Param<"uint32_t*", "ParamB", "Parameter B description">,
+ ];
+ let returns = [
+ Return<"OFFLOAD_ERRC_INVALID_VALUE", ["When a value is invalid"]>
+ ];
+}
+
+
+// The validation function should call the implementation function
+// CHECK: FunctionA_val
+// CHECK: return FunctionA_impl(ParamA, ParamB);
+
+// CHECK: offload_result_t{{.*}} FunctionA(
+
+// The entry point should print tracing output if enabled
+// CHECK: if (offloadConfig().TracingEnabled) {
+// CHECK-NEXT: "---> FunctionA";
+
+// CHECK: Result = FunctionA_val(ParamA, ParamB);
+
+// Tracing should construct a param struct for printing
+// CHECK: if (offloadConfig().TracingEnabled) {
+// CHECK: function_a_params_t Params = {&ParamA, &ParamB};
+
+// CHECK: return Result;
diff --git a/offload/test/tools/offload-tblgen/functions_basic.td b/offload/test/tools/offload-tblgen/functions_basic.td
new file mode 100644
index 00000000000000..6601746a727b00
--- /dev/null
+++ b/offload/test/tools/offload-tblgen/functions_basic.td
@@ -0,0 +1,39 @@
+// RUN: %offload-tblgen -gen-api -I %S/../../../new-api/API %s | %fcheck-generic --check-prefix=CHECK-API
+// RUN: %offload-tblgen -gen-exports -I %S/../../../new-api/API %s | %fcheck-generic --check-prefix=CHECK-EXPORTS
+// RUN: %offload-tblgen -gen-func-names -I %S/../../../new-api/API %s | %fcheck-generic --check-prefix=CHECK-FUNC-MACRO
+
+// Check basic support for API functions
+
+include "APIDefs.td"
+
+def : Function {
+ let name = "FunctionA";
+ let desc = "Function A description";
+ let details = [ "Function A detailed information" ];
+ let params = [
+ Param<"uint32_t", "ParamA", "Parameter A description">,
+ Param<"uint32_t*", "ParamB", "Parameter B description">,
+ ];
+ let returns = [
+ Return<"OFFLOAD_ERRC_INVALID_VALUE", ["When a value is invalid"]>
+ ];
+}
+
+// CHECK-API: /// @brief Function A description
+// CHECK-API: /// @details
+// CHECK-API-NEXT: Function A detailed information
+// CHECK-API: /// @returns
+// CHECK-API: OFFLOAD_ERRC_INVALID_VALUE
+// CHECK-API-NEXT: When a value is invalid
+
+// CHECK-API: offload_result_t
+// CHECK-API-SAME: FunctionA
+
+// CHECK-API: // Parameter A description
+// CHECK-API-NEXT: uint32_t ParamA
+// CHECK-API: // Parameter B description
+// CHECK-API-NEXT: uint32_t* ParamB
+
+// CHECK-EXPORTS: FunctionA
+
+// CHECK-FUNC-MACRO: OFFLOAD_FUNC(FunctionA)
diff --git a/offload/test/tools/offload-tblgen/functions_code_loc.td b/offload/test/tools/offload-tblgen/functions_code_loc.td
new file mode 100644
index 00000000000000..4c8d3688566c35
--- /dev/null
+++ b/offload/test/tools/offload-tblgen/functions_code_loc.td
@@ -0,0 +1,26 @@
+// RUN: %offload-tblgen -gen-api -I %S/../../../new-api/API %s | %fcheck-generic --check-prefix=CHECK-API
+// RUN: %offload-tblgen -gen-exports -I %S/../../../new-api/API %s | %fcheck-generic --check-prefix=CHECK-EXPORTS
+// RUN: %offload-tblgen -gen-func-names -I %S/../../../new-api/API %s | %fcheck-generic --check-prefix=CHECK-FUNC-MACRO
+
+// Check that the function variant with code location information is generated
+// and is otherwise the same as the regular function
+
+include "APIDefs.td"
+
+def : Function {
+ let name = "FunctionA";
+ let desc = "Function A description";
+ let details = [ "Function A detailed information" ];
+ let params = [
+ Param<"uint32_t", "ParamA", "Parameter A description">,
+ Param<"uint32_t*", "ParamB", "Parameter B description">,
+ ];
+ let returns = [
+ Return<"OFFLOAD_ERRC_INVALID_VALUE", ["When a value is invalid"]>
+ ];
+}
+
+// CHECK-API-DAG: offload_result_t{{.*}} FunctionA
+// CHECK-API-DAG: offload_result_t{{.*}} FunctionAWithCodeLoc
+// CHECK-EXPORTS: FunctionAWithCodeLoc
+// CHECK-FUNC-MACRO: OFFLOAD_FUNC(FunctionAWithCodeLoc)
diff --git a/offload/test/tools/offload-tblgen/print_enum.td b/offload/test/tools/offload-tblgen/print_enum.td
new file mode 100644
index 00000000000000..1e1d7f57218d0a
--- /dev/null
+++ b/offload/test/tools/offload-tblgen/print_enum.td
@@ -0,0 +1,34 @@
+// RUN: %offload-tblgen -gen-print-header -I %S/../../../new-api/API %s | %fcheck-generic
+
+// Check that print helpers are created for enums
+
+include "APIDefs.td"
+
+def : Enum {
+ let name = "my_enum_t";
+ let desc = "An example enum";
+ let etors =[
+ Etor<"VALUE_ONE", "The first enum value">,
+ Etor<"VALUE_TWO", "The second enum value">,
+ Etor<"VALUE_THREE", "The third enum value">,
+ Etor<"VALUE_FOUR", "The fourth enum value">,
+ ];
+}
+
+// CHECK: inline std::ostream &operator<<(std::ostream &os, enum my_enum_t value)
+// CHECK: switch (value) {
+// CHECK: case MY_ENUM_VALUE_ONE:
+// CHECK: os << "MY_ENUM_VALUE_ONE";
+// CHECK: break;
+// CHECK: case MY_ENUM_VALUE_TWO:
+// CHECK: os << "MY_ENUM_VALUE_TWO";
+// CHECK: break;
+// CHECK: case MY_ENUM_VALUE_THREE:
+// CHECK: os << "MY_ENUM_VALUE_THREE";
+// CHECK: break;
+// CHECK: case MY_ENUM_VALUE_FOUR:
+// CHECK: os << "MY_ENUM_VALUE_FOUR";
+// CHECK: break;
+// CHECK: default:
+// CHECK: os << "unknown enumerator";
+// CHECK: break;
diff --git a/offload/test/tools/offload-tblgen/print_function.td b/offload/test/tools/offload-tblgen/print_function.td
new file mode 100644
index 00000000000000..2a9cce724eda94
--- /dev/null
+++ b/offload/test/tools/offload-tblgen/print_function.td
@@ -0,0 +1,38 @@
+// RUN: %offload-tblgen -gen-print-header -I %S/../../../new-api/API %s | %fcheck-generic --check-prefix=CHECK-PRINT
+// RUN: %offload-tblgen -gen-api -I %S/../../../new-api/API %s | %fcheck-generic --check-prefix=CHECK-API
+
+// Check that print helpers are created for functions
+
+include "APIDefs.td"
+
+def : Handle {
+ let name = "offload_foo_handle_t";
+ let desc = "Example handle type";
+}
+
+def : Function {
+ let name = "FunctionA";
+ let desc = "Function A description";
+ let details = [ "Function A detailed information" ];
+ let params = [
+ Param<"uint32_t", "ParamValue", "A plain value parameter">,
+ Param<"offload_foo_handle_t", "ParamHandle", "A handle parameter">,
+ Param<"uint32_t*", "ParamPointer", "A pointer parameter">,
+ ];
+ let returns = [];
+}
+
+// CHECK-API: typedef struct function_a_params_t {
+// CHECK-API-NEXT: uint32_t* pParamValue;
+// CHECK-API-NEXT: offload_foo_handle_t* pParamHandle;
+// CHECK-API-NEXT: uint32_t** pParamPointer;
+
+// CHECK-PRINT: inline std::ostream &operator<<(std::ostream &os, const struct function_a_params_t *params)
+// CHECK-PRINT: os << ".ParamValue = ";
+// CHECK-PRINT: os << *params->pParamValue;
+// CHECK-PRINT: os << ", ";
+// CHECK-PRINT: os << ".ParamHandle = ";
+// CHECK-PRINT: printPtr(os, *params->pParamHandle);
+// CHECK-PRINT: os << ", ";
+// CHECK-PRINT: os << ".ParamPointer = ";
+// CHECK-PRINT: printPtr(os, *params->pParamPointer);
diff --git a/offload/tools/offload-tblgen/EntryPointGen.cpp b/offload/tools/offload-tblgen/EntryPointGen.cpp
index 67e6af671e4f36..82d4f85126dffa 100644
--- a/offload/tools/offload-tblgen/EntryPointGen.cpp
+++ b/offload/tools/offload-tblgen/EntryPointGen.cpp
@@ -83,7 +83,7 @@ static void EmitEntryPointFunc(const FunctionRec &F, raw_ostream &OS) {
// Emit post-call prints
OS << TAB_1 "if (offloadConfig().TracingEnabled) {\n";
if (F.getParams().size() > 0) {
- OS << formatv(TAB_2 "{0} Params = {{ ", F.getParamStructName());
+ OS << formatv(TAB_2 "{0} Params = {{", F.getParamStructName());
for (const auto &Param : F.getParams()) {
OS << "&" << Param.getName();
if (Param != F.getParams().back()) {
diff --git a/offload/tools/offload-tblgen/FuncsGen.cpp b/offload/tools/offload-tblgen/FuncsGen.cpp
index e0152053c9e19c..17d8bc375e2bea 100644
--- a/offload/tools/offload-tblgen/FuncsGen.cpp
+++ b/offload/tools/offload-tblgen/FuncsGen.cpp
@@ -33,6 +33,10 @@ void EmitOffloadFuncNames(RecordKeeper &Records, raw_ostream &OS) {
FunctionRec FR{R};
OS << formatv("OFFLOAD_FUNC({0})", FR.getName()) << "\n";
}
+ for (auto *R : Records.getAllDerivedDefinitions("Function")) {
+ FunctionRec FR{R};
+ OS << formatv("OFFLOAD_FUNC({0}WithCodeLoc)", FR.getName()) << "\n";
+ }
OS << "\n#undef OFFLOAD_FUNC\n";
}
@@ -44,6 +48,9 @@ void EmitOffloadExports(RecordKeeper &Records, raw_ostream &OS) {
for (auto *R : Records.getAllDerivedDefinitions("Function")) {
OS << formatv(TAB_2 "{0};\n", FunctionRec(R).getName());
}
+ for (auto *R : Records.getAllDerivedDefinitions("Function")) {
+ OS << formatv(TAB_2 "{0}WithCodeLoc;\n", FunctionRec(R).getName());
+ }
OS << TAB_1 "local:\n";
OS << TAB_2 "*;\n";
OS << "};\n";
diff --git a/offload/tools/offload-tblgen/PrintGen.cpp b/offload/tools/offload-tblgen/PrintGen.cpp
index e8dc84f9170fdf..e0a31c8e9d86e4 100644
--- a/offload/tools/offload-tblgen/PrintGen.cpp
+++ b/offload/tools/offload-tblgen/PrintGen.cpp
@@ -115,7 +115,7 @@ static void EmitFunctionParamStructPrint(const FunctionRec &Func,
}
OS << formatv(R"(
-inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct {0} *params) {{
+inline std::ostream &operator<<(std::ostream &os, const struct {0} *params) {{
)",
Func.getParamStructName());
>From 87cfd2a5594b0953c4e9b5434a70f08304b46040 Mon Sep 17 00:00:00 2001
From: Callum Fare <callum at codeplay.com>
Date: Mon, 28 Oct 2024 14:27:10 +0000
Subject: [PATCH 16/24] Add additional offload-tblgen tests and associated
fixes
---
offload/new-api/API/Platform.td | 2 +-
offload/new-api/include/offload_api.h | 24 +++---
.../offload-tblgen/functions_ranged_param.td | 36 +++++++++
.../tools/offload-tblgen/type_tagged_enum.td | 76 +++++++++++++++++++
offload/tools/offload-tblgen/APIGen.cpp | 8 +-
offload/tools/offload-tblgen/PrintGen.cpp | 2 +-
6 files changed, 133 insertions(+), 15 deletions(-)
create mode 100644 offload/test/tools/offload-tblgen/functions_ranged_param.td
create mode 100644 offload/test/tools/offload-tblgen/type_tagged_enum.td
diff --git a/offload/new-api/API/Platform.td b/offload/new-api/API/Platform.td
index c9b5d7d1fb99f9..e877caef0869f9 100644
--- a/offload/new-api/API/Platform.td
+++ b/offload/new-api/API/Platform.td
@@ -50,7 +50,7 @@ def : Enum {
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<"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 native backend of the platform.">
];
diff --git a/offload/new-api/include/offload_api.h b/offload/new-api/include/offload_api.h
index 87325ad46eaade..f930210eb37a9e 100644
--- a/offload/new-api/include/offload_api.h
+++ b/offload/new-api/include/offload_api.h
@@ -213,16 +213,16 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetCount(
///////////////////////////////////////////////////////////////////////////////
/// @brief Supported platform info
typedef enum offload_platform_info_t {
- /// The string denoting name of the platform. The size of the info needs to be
- /// dynamically queried.
+ /// [char[]] 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.
+ /// [char[]] 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.
+ /// [char[]] The string denoting the version of the platform. The size of the
+ /// info needs to be dynamically queried.
OFFLOAD_PLATFORM_INFO_VERSION = 2,
- /// The native backend of the platform.
+ /// [offload_platform_backend_t] The native backend of the platform.
OFFLOAD_PLATFORM_INFO_BACKEND = 3,
/// @cond
OFFLOAD_PLATFORM_INFO_FORCE_UINT32 = 0x7fffffff
@@ -328,15 +328,15 @@ typedef enum offload_device_type_t {
///////////////////////////////////////////////////////////////////////////////
/// @brief Supported device info
typedef enum offload_device_info_t {
- /// type of the device
+ /// [offload_device_type_t] type of the device
OFFLOAD_DEVICE_INFO_TYPE = 0,
- /// the platform associated with the device
+ /// [offload_platform_handle_t] the platform associated with the device
OFFLOAD_DEVICE_INFO_PLATFORM = 1,
- /// Device name
+ /// [char[]] Device name
OFFLOAD_DEVICE_INFO_NAME = 2,
- /// Device vendor
+ /// [char[]] Device vendor
OFFLOAD_DEVICE_INFO_VENDOR = 3,
- /// Driver version
+ /// [char[]] Driver version
OFFLOAD_DEVICE_INFO_DRIVER_VERSION = 4,
/// @cond
OFFLOAD_DEVICE_INFO_FORCE_UINT32 = 0x7fffffff
diff --git a/offload/test/tools/offload-tblgen/functions_ranged_param.td b/offload/test/tools/offload-tblgen/functions_ranged_param.td
new file mode 100644
index 00000000000000..efa8bae5290ec2
--- /dev/null
+++ b/offload/test/tools/offload-tblgen/functions_ranged_param.td
@@ -0,0 +1,36 @@
+// RUN: %offload-tblgen -gen-print-header -I %S/../../../new-api/API %s | %fcheck-generic
+
+// Check that ranged function parameters are implemented correctly. These
+// are pointers to an array of an arbitrary size. Their size is described as a
+// range between two values. This is typically between 0 and a parameter such
+// as NumItems. The range information helps the printing code print the entire
+// range of the output rather than just the pointer or the first element.
+
+include "APIDefs.td"
+
+def : Handle {
+ let name = "some_handle_t";
+ let desc = "An example handle type";
+}
+
+def : Function {
+ let name = "FunctionA";
+ let desc = "Function A description";
+ let details = [ "Function A detailed information" ];
+ let params = [
+ Param<"size_t", "OutCount", "the number of things to write out", PARAM_IN>,
+ RangedParam<"some_handle_t*", "OutPtr", "pointer to the output things.", PARAM_OUT,
+ Range<"0", "OutCount">>
+ ];
+ let returns = [];
+}
+
+// CHECK: inline std::ostream &operator<<(std::ostream &os, const struct function_a_params_t *params) {
+// CHECK: os << ".OutPtr = ";
+// CHECK: for (size_t i = 0; i < *params->pOutCount; i++) {
+// CHECK: if (i > 0) {
+// CHECK: os << ", ";
+// CHECK: }
+// CHECK: printPtr(os, (*params->pOutPtr)[i]);
+// CHECK: }
+// CHECK: os << "}";
diff --git a/offload/test/tools/offload-tblgen/type_tagged_enum.td b/offload/test/tools/offload-tblgen/type_tagged_enum.td
new file mode 100644
index 00000000000000..ff9c91f88c5382
--- /dev/null
+++ b/offload/test/tools/offload-tblgen/type_tagged_enum.td
@@ -0,0 +1,76 @@
+// RUN: %offload-tblgen -gen-api -I %S/../../../new-api/API %s | %fcheck-generic --check-prefix=CHECK-API
+// RUN: %offload-tblgen -gen-print-header -I %S/../../../new-api/API %s | %fcheck-generic --check-prefix=CHECK-PRINT
+
+// Check that type-tagged enumerators are implemented correctly. They enable
+// functions to return data of an arbitrary type and size via a void*, using
+// the value of an enum parameter to indicate which type is being returned.
+// This allows, for example, for a single offloadDeviceGetInfo function, rather
+// than requiring a separate entry point for every possible query.
+
+include "APIDefs.td"
+
+def : Handle {
+ let name = "some_handle_t";
+ let desc = "An example handle type";
+}
+
+def : Enum {
+ let name = "my_type_tagged_enum_t";
+ let desc = "Example type tagged enum";
+ let is_typed = 1;
+ let etors = [
+ TaggedEtor<"VALUE_ONE", "uint32_t", "Value one.">,
+ TaggedEtor<"VALUE_TWO", "char[]", "Value two.">,
+ TaggedEtor<"VALUE_THREE", "some_handle_t", "Value three.">
+ ];
+}
+
+// Check the tagged types appear in the comments
+// CHECK-API: typedef enum my_type_tagged_enum_t {
+// CHECK-API-NEXT: [uint32_t] Value one.
+// CHECK-API-NEXT: MY_TYPE_TAGGED_ENUM_VALUE_ONE = 0,
+// CHECK-API-NEXT: [char[]] Value two.
+// CHECK-API-NEXT: MY_TYPE_TAGGED_ENUM_VALUE_TWO = 1,
+// CHECK-API-NEXT: [some_handle_t] Value three.
+// CHECK-API-NEXT: MY_TYPE_TAGGED_ENUM_VALUE_THREE = 2,
+
+def : Function {
+ let name = "FunctionA";
+ let desc = "Function A description";
+ let details = [ "Function A detailed information" ];
+ let params = [
+ Param<"my_type_tagged_enum_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 to the real number of bytes needed to return the info "
+ "then the OFFLOAD_ERRC_INVALID_SIZE error is returned and PropValue is not used.", PARAM_OUT,
+ TypeInfo<"PropName" , "PropSize">>
+ ];
+ let returns = [];
+}
+
+// Check that a tagged enum print function definition is generated
+// CHECK-PRINT: void printTagged(std::ostream &os, const void *ptr, my_type_tagged_enum_t value, size_t size) {
+// CHECK-PRINT: case MY_TYPE_TAGGED_ENUM_VALUE_ONE: {
+// CHECK-PRINT: const uint32_t * const tptr = (const uint32_t * const)ptr;
+// CHECK-PRINT: os << (const void *)tptr << " (";
+// CHECK-PRINT: os << *tptr;
+// CHECK-PRINT: os << ")";
+// CHECK-PRINT: break;
+// CHECK-PRINT: }
+// CHECK-PRINT: case MY_TYPE_TAGGED_ENUM_VALUE_TWO: {
+// CHECK-PRINT: printPtr(os, (const char*) ptr);
+// CHECK-PRINT: break;
+// CHECK-PRINT: }
+// CHECK-PRINT: case MY_TYPE_TAGGED_ENUM_VALUE_THREE: {
+// CHECK-PRINT: const some_handle_t * const tptr = (const some_handle_t * const)ptr;
+// CHECK-PRINT: os << (const void *)tptr << " (";
+// CHECK-PRINT: os << *tptr;
+// CHECK-PRINT: os << ")";
+// CHECK-PRINT: break;
+// CHECK-PRINT: }
+
+// Check that the tagged type information is used when printing function parameters
+// CHECK-PRINT: std::ostream &operator<<(std::ostream &os, const struct function_a_params_t *params) {
+// CHECK-PRINT: os << ".PropValue = "
+// CHECK-PRINT-NEXT: printTagged(os, *params->pPropValue, *params->pPropName, *params->pPropSize);
diff --git a/offload/tools/offload-tblgen/APIGen.cpp b/offload/tools/offload-tblgen/APIGen.cpp
index 29b5d2efb16f2d..2d5f6d538199fa 100644
--- a/offload/tools/offload-tblgen/APIGen.cpp
+++ b/offload/tools/offload-tblgen/APIGen.cpp
@@ -125,7 +125,13 @@ static void ProcessEnum(const EnumRec &Enum, raw_ostream &OS) {
uint32_t EtorVal = 0;
for (const auto &EnumVal : Enum.getValues()) {
- OS << TAB_1 << MakeComment(EnumVal.getDesc());
+ if (Enum.isTyped()) {
+ OS << MakeComment(
+ formatv("[{0}] {1}", EnumVal.getTaggedType(), EnumVal.getDesc())
+ .str());
+ } else {
+ OS << MakeComment(EnumVal.getDesc());
+ }
OS << formatv(TAB_1 "{0}_{1} = {2},\n", Enum.getEnumValNamePrefix(),
EnumVal.getName(), EtorVal++);
}
diff --git a/offload/tools/offload-tblgen/PrintGen.cpp b/offload/tools/offload-tblgen/PrintGen.cpp
index e0a31c8e9d86e4..f5edbed88f184e 100644
--- a/offload/tools/offload-tblgen/PrintGen.cpp
+++ b/offload/tools/offload-tblgen/PrintGen.cpp
@@ -123,7 +123,7 @@ inline std::ostream &operator<<(std::ostream &os, const struct {0} *params) {{
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",
+ 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";
>From f4e5f487a869404aefbe454ec2af4936ec0402e2 Mon Sep 17 00:00:00 2001
From: Callum Fare <callum at codeplay.com>
Date: Mon, 28 Oct 2024 14:37:08 +0000
Subject: [PATCH 17/24] Add version info to the API definition
---
offload/new-api/API/Common.td | 18 ++++++++++++++++++
offload/new-api/include/offload_api.h | 18 ++++++++++++++++++
2 files changed, 36 insertions(+)
diff --git a/offload/new-api/API/Common.td b/offload/new-api/API/Common.td
index d9c356c55bf5c0..3350219ec2cce6 100644
--- a/offload/new-api/API/Common.td
+++ b/offload/new-api/API/Common.td
@@ -1,3 +1,21 @@
+def : Macro {
+ let name = "OFFLOAD_VERSION_MAJOR";
+ let desc = "Major version of the Offload API";
+ let value = "0";
+}
+
+def : Macro {
+ let name = "OFFLOAD_VERSION_MINOR";
+ let desc = "Minor version of the Offload API";
+ let value = "0";
+}
+
+def : Macro {
+ let name = "OFFLOAD_VERSION_PATCH";
+ let desc = "Patch version of the Offload API";
+ let value = "1";
+}
+
def : Macro {
let name = "OFFLOAD_APICALL";
let desc = "Calling convention for all API functions";
diff --git a/offload/new-api/include/offload_api.h b/offload/new-api/include/offload_api.h
index f930210eb37a9e..66732a35b5a76d 100644
--- a/offload/new-api/include/offload_api.h
+++ b/offload/new-api/include/offload_api.h
@@ -17,6 +17,24 @@
extern "C" {
#endif
+///////////////////////////////////////////////////////////////////////////////
+#ifndef OFFLOAD_VERSION_MAJOR
+/// @brief Major version of the Offload API
+#define OFFLOAD_VERSION_MAJOR 0
+#endif // OFFLOAD_VERSION_MAJOR
+
+///////////////////////////////////////////////////////////////////////////////
+#ifndef OFFLOAD_VERSION_MINOR
+/// @brief Minor version of the Offload API
+#define OFFLOAD_VERSION_MINOR 0
+#endif // OFFLOAD_VERSION_MINOR
+
+///////////////////////////////////////////////////////////////////////////////
+#ifndef OFFLOAD_VERSION_PATCH
+/// @brief Patch version of the Offload API
+#define OFFLOAD_VERSION_PATCH 1
+#endif // OFFLOAD_VERSION_PATCH
+
///////////////////////////////////////////////////////////////////////////////
#ifndef OFFLOAD_APICALL
#if defined(_WIN32)
>From 97d5b70c5ad003889f848468849919c815ee1e61 Mon Sep 17 00:00:00 2001
From: Callum Fare <callum at codeplay.com>
Date: Wed, 30 Oct 2024 11:16:16 +0000
Subject: [PATCH 18/24] Fix version query; misc style fixes
---
offload/new-api/API/APIDefs.td | 4 +--
offload/new-api/API/Device.td | 11 ++----
offload/new-api/API/Platform.td | 7 +---
offload/new-api/API/README.md | 2 +-
offload/new-api/include/offload_api.h | 52 +++++++++++----------------
offload/new-api/src/offload_impl.cpp | 9 +++--
6 files changed, 31 insertions(+), 54 deletions(-)
diff --git a/offload/new-api/API/APIDefs.td b/offload/new-api/API/APIDefs.td
index 64785217b48849..66dce8025a3e7b 100644
--- a/offload/new-api/API/APIDefs.td
+++ b/offload/new-api/API/APIDefs.td
@@ -133,8 +133,8 @@ class AddPointerChecksToReturns<list<Param> Params, list<Return> Returns> {
}
defvar DefaultReturns = [Return<PREFIX#"_RESULT_SUCCESS">,
- Return<PREFIX#"_RESULT_ERROR_UNINITIALIZED">,
- Return<PREFIX#"_RESULT_ERROR_DEVICE_LOST">];
+ Return<PREFIX#"_ERRC_UNINITIALIZED">,
+ Return<PREFIX#"_ERRC_DEVICE_LOST">];
class APIObject {
string name;
diff --git a/offload/new-api/API/Device.td b/offload/new-api/API/Device.td
index bc216708226c6f..6a931a8172ad70 100644
--- a/offload/new-api/API/Device.td
+++ b/offload/new-api/API/Device.td
@@ -49,7 +49,6 @@ def : Function {
let desc = "Retrieves devices within a platform";
let details = [
"Multiple calls to this function will return identical device handles, in the same order.",
- "The application may call this function from simultaneous threads, the implementation must be thread-safe"
];
let params = [
Param<"offload_platform_handle_t", "Platform", "handle of the platform instance", PARAM_IN>,
@@ -68,10 +67,7 @@ def : Function {
def : Function {
let name = "offloadDeviceGetInfo";
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."
- ];
+ let details = [];
let params = [
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>,
@@ -95,10 +91,7 @@ def : Function {
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 details = [];
let params = [
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>,
diff --git a/offload/new-api/API/Platform.td b/offload/new-api/API/Platform.td
index e877caef0869f9..d2d0bdf176f9f2 100644
--- a/offload/new-api/API/Platform.td
+++ b/offload/new-api/API/Platform.td
@@ -72,8 +72,6 @@ def : Function {
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."
];
let params = [
Param<"offload_platform_handle_t", "Platform", "handle of the platform", PARAM_IN>,
@@ -99,10 +97,7 @@ def : Function {
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 details = [];
let params = [
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>,
diff --git a/offload/new-api/API/README.md b/offload/new-api/API/README.md
index ab1db704404f35..b0b3e5c6620db1 100644
--- a/offload/new-api/API/README.md
+++ b/offload/new-api/API/README.md
@@ -147,4 +147,4 @@ 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
+be added to `src/offload_impl.cpp`
diff --git a/offload/new-api/include/offload_api.h b/offload/new-api/include/offload_api.h
index 66732a35b5a76d..83dcb41634c3c4 100644
--- a/offload/new-api/include/offload_api.h
+++ b/offload/new-api/include/offload_api.h
@@ -165,8 +165,8 @@ typedef struct offload_code_location_t {
///
/// @returns
/// - ::OFFLOAD_RESULT_SUCCESS
-/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
-/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
+/// - ::OFFLOAD_ERRC_UNINITIALIZED
+/// - ::OFFLOAD_ERRC_DEVICE_LOST
/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadInit();
@@ -181,8 +181,8 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadInit();
///
/// @returns
/// - ::OFFLOAD_RESULT_SUCCESS
-/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
-/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
+/// - ::OFFLOAD_ERRC_UNINITIALIZED
+/// - ::OFFLOAD_ERRC_DEVICE_LOST
/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadShutDown();
@@ -196,8 +196,8 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadShutDown();
///
/// @returns
/// - ::OFFLOAD_RESULT_SUCCESS
-/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
-/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
+/// - ::OFFLOAD_ERRC_UNINITIALIZED
+/// - ::OFFLOAD_ERRC_DEVICE_LOST
/// - ::OFFLOAD_ERRC_INVALID_SIZE
/// + `NumEntries == 0`
/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
@@ -219,8 +219,8 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGet(
///
/// @returns
/// - ::OFFLOAD_RESULT_SUCCESS
-/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
-/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
+/// - ::OFFLOAD_ERRC_UNINITIALIZED
+/// - ::OFFLOAD_ERRC_DEVICE_LOST
/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
/// + `NULL == NumPlatforms`
@@ -268,14 +268,12 @@ typedef enum offload_platform_backend_t {
///
/// @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.
+/// required for the given query.
///
/// @returns
/// - ::OFFLOAD_RESULT_SUCCESS
-/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
-/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
+/// - ::OFFLOAD_ERRC_UNINITIALIZED
+/// - ::OFFLOAD_ERRC_DEVICE_LOST
/// - ::OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION
/// + If `PropName` is not supported by the platform.
/// - ::OFFLOAD_ERRC_INVALID_SIZE
@@ -304,13 +302,11 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfo(
/// @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_UNINITIALIZED
+/// - ::OFFLOAD_ERRC_DEVICE_LOST
/// - ::OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION
/// + If `PropName` is not supported by the platform.
/// - ::OFFLOAD_ERRC_INVALID_PLATFORM
@@ -369,8 +365,8 @@ typedef enum offload_device_info_t {
///
/// @returns
/// - ::OFFLOAD_RESULT_SUCCESS
-/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
-/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
+/// - ::OFFLOAD_ERRC_UNINITIALIZED
+/// - ::OFFLOAD_ERRC_DEVICE_LOST
/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
/// + `NULL == Platform`
/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
@@ -387,13 +383,11 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetCount(
/// @details
/// - Multiple calls to this function will return identical device handles,
/// in the same order.
-/// - 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_ERRC_UNINITIALIZED
+/// - ::OFFLOAD_ERRC_DEVICE_LOST
/// - ::OFFLOAD_ERRC_INVALID_SIZE
/// + `NumEntries == 0`
/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
@@ -415,13 +409,11 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGet(
/// @brief Queries the given property of the 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_ERRC_UNINITIALIZED
+/// - ::OFFLOAD_ERRC_DEVICE_LOST
/// - ::OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION
/// + If `PropName` is not supported by the device.
/// - ::OFFLOAD_ERRC_INVALID_SIZE
@@ -449,13 +441,11 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetInfo(
/// @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_UNINITIALIZED
+/// - ::OFFLOAD_ERRC_DEVICE_LOST
/// - ::OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION
/// + If `PropName` is not supported by the device.
/// - ::OFFLOAD_ERRC_INVALID_DEVICE
diff --git a/offload/new-api/src/offload_impl.cpp b/offload/new-api/src/offload_impl.cpp
index 32672d572f8fb4..d62e4831e17756 100644
--- a/offload/new-api/src/offload_impl.cpp
+++ b/offload/new-api/src/offload_impl.cpp
@@ -80,9 +80,6 @@ offload_impl_result_t offloadInit_impl() {
offload_impl_result_t offloadShutDown_impl() { return OFFLOAD_RESULT_SUCCESS; }
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.
*NumPlatforms = Platforms().size();
return OFFLOAD_RESULT_SUCCESS;
}
@@ -116,8 +113,10 @@ offload_impl_result_t offloadPlatformGetInfoImplDetail(
// TODO: Implement this
return ReturnValue("Unknown platform vendor");
case OFFLOAD_PLATFORM_INFO_VERSION: {
- // TODO: Implement this
- return ReturnValue("v0.0.0");
+ return ReturnValue(formatv("v{0}.{1}.{2}", OFFLOAD_VERSION_MAJOR,
+ OFFLOAD_VERSION_MINOR, OFFLOAD_VERSION_PATCH)
+ .str()
+ .c_str());
}
case OFFLOAD_PLATFORM_INFO_BACKEND: {
auto PluginName = Platform->Plugin->getName();
>From fcd34d54977ae1f24ec0af0075b9df1274ee11d3 Mon Sep 17 00:00:00 2001
From: Callum Fare <callum at codeplay.com>
Date: Thu, 31 Oct 2024 10:31:03 +0000
Subject: [PATCH 19/24] Change prefix from `offload` to `ol`
---
offload/new-api/API/APIDefs.td | 2 +-
offload/new-api/API/Common.td | 40 +-
offload/new-api/API/Device.td | 44 +-
offload/new-api/API/Platform.td | 42 +-
offload/new-api/API/README.md | 4 +-
offload/new-api/include/offload_api.h | 542 +++++++++---------
.../new-api/include/offload_entry_points.inc | 306 +++++-----
offload/new-api/include/offload_exports | 40 +-
offload/new-api/include/offload_funcs.inc | 40 +-
offload/new-api/include/offload_impl.hpp | 26 +-
.../include/offload_impl_func_decls.inc | 50 +-
offload/new-api/include/offload_print.hpp | 241 ++++----
offload/new-api/src/helpers.hpp | 32 +-
offload/new-api/src/offload_impl.cpp | 152 +++--
offload/new-api/src/offload_lib.cpp | 4 +-
.../tools/offload-tblgen/type_tagged_enum.td | 2 +-
offload/tools/offload-tblgen/APIGen.cpp | 4 +-
.../tools/offload-tblgen/EntryPointGen.cpp | 2 +-
offload/tools/offload-tblgen/GenCommon.hpp | 4 +-
offload/tools/offload-tblgen/PrintGen.cpp | 10 +-
offload/unittests/OffloadAPI/CMakeLists.txt | 16 +-
.../OffloadAPI/common/environment.cpp | 31 +-
.../OffloadAPI/common/environment.hpp | 4 +-
.../unittests/OffloadAPI/common/fixtures.hpp | 12 +-
.../device/offloadDeviceGetCount.cpp | 30 -
.../device/offloadDeviceGetInfo.cpp | 80 ---
.../device/offloadDeviceGetInfoSize.cpp | 61 --
...offloadDeviceInfo.hpp => olDeviceInfo.hpp} | 13 +-
.../{offloadDeviceGet.cpp => olGetDevice.cpp} | 20 +-
.../OffloadAPI/device/olGetDeviceCount.cpp | 29 +
.../OffloadAPI/device/olGetDeviceInfo.cpp | 76 +++
.../OffloadAPI/device/olGetDeviceInfoSize.cpp | 58 ++
.../platform/offloadPlatformGet.cpp | 29 -
.../platform/offloadPlatformGetInfo.cpp | 78 ---
.../platform/offloadPlatformGetInfoSize.cpp | 58 --
.../OffloadAPI/platform/olGetPlatform.cpp | 28 +
...ormGetCount.cpp => olGetPlatformCount.cpp} | 13 +-
.../OffloadAPI/platform/olGetPlatformInfo.cpp | 76 +++
.../platform/olGetPlatformInfoSize.cpp | 57 ++
...oadPlatformInfo.hpp => olPlatformInfo.hpp} | 11 +-
40 files changed, 1153 insertions(+), 1214 deletions(-)
delete mode 100644 offload/unittests/OffloadAPI/device/offloadDeviceGetCount.cpp
delete mode 100644 offload/unittests/OffloadAPI/device/offloadDeviceGetInfo.cpp
delete mode 100644 offload/unittests/OffloadAPI/device/offloadDeviceGetInfoSize.cpp
rename offload/unittests/OffloadAPI/device/{offloadDeviceInfo.hpp => olDeviceInfo.hpp} (52%)
rename offload/unittests/OffloadAPI/device/{offloadDeviceGet.cpp => olGetDevice.cpp} (52%)
create mode 100644 offload/unittests/OffloadAPI/device/olGetDeviceCount.cpp
create mode 100644 offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp
create mode 100644 offload/unittests/OffloadAPI/device/olGetDeviceInfoSize.cpp
delete mode 100644 offload/unittests/OffloadAPI/platform/offloadPlatformGet.cpp
delete mode 100644 offload/unittests/OffloadAPI/platform/offloadPlatformGetInfo.cpp
delete mode 100644 offload/unittests/OffloadAPI/platform/offloadPlatformGetInfoSize.cpp
create mode 100644 offload/unittests/OffloadAPI/platform/olGetPlatform.cpp
rename offload/unittests/OffloadAPI/platform/{offloadPlatformGetCount.cpp => olGetPlatformCount.cpp} (50%)
create mode 100644 offload/unittests/OffloadAPI/platform/olGetPlatformInfo.cpp
create mode 100644 offload/unittests/OffloadAPI/platform/olGetPlatformInfoSize.cpp
rename offload/unittests/OffloadAPI/platform/{offloadPlatformInfo.hpp => olPlatformInfo.hpp} (55%)
diff --git a/offload/new-api/API/APIDefs.td b/offload/new-api/API/APIDefs.td
index 66dce8025a3e7b..60c1b85d26911e 100644
--- a/offload/new-api/API/APIDefs.td
+++ b/offload/new-api/API/APIDefs.td
@@ -14,7 +14,7 @@
// Prefix for API naming. This could be hard-coded in the future when a value
// is agreed upon.
-defvar PREFIX = "OFFLOAD";
+defvar PREFIX = "OL";
defvar prefix = !tolower(PREFIX);
// Parameter flags
diff --git a/offload/new-api/API/Common.td b/offload/new-api/API/Common.td
index 3350219ec2cce6..5b19d1d47129ef 100644
--- a/offload/new-api/API/Common.td
+++ b/offload/new-api/API/Common.td
@@ -1,23 +1,23 @@
def : Macro {
- let name = "OFFLOAD_VERSION_MAJOR";
+ let name = "OL_VERSION_MAJOR";
let desc = "Major version of the Offload API";
let value = "0";
}
def : Macro {
- let name = "OFFLOAD_VERSION_MINOR";
+ let name = "OL_VERSION_MINOR";
let desc = "Minor version of the Offload API";
let value = "0";
}
def : Macro {
- let name = "OFFLOAD_VERSION_PATCH";
+ let name = "OL_VERSION_PATCH";
let desc = "Patch version of the Offload API";
let value = "1";
}
def : Macro {
- let name = "OFFLOAD_APICALL";
+ let name = "OL_APICALL";
let desc = "Calling convention for all API functions";
let condition = "defined(_WIN32)";
let value = "__cdecl";
@@ -25,7 +25,7 @@ def : Macro {
}
def : Macro {
- let name = "OFFLOAD_APIEXPORT";
+ let name = "OL_APIEXPORT";
let desc = "Microsoft-specific dllexport storage-class attribute";
let condition = "defined(_WIN32)";
let value = "__declspec(dllexport)";
@@ -33,14 +33,14 @@ def : Macro {
}
def : Macro {
- let name = "OFFLOAD_DLLEXPORT";
+ let name = "OL_DLLEXPORT";
let desc = "Microsoft-specific dllexport storage-class attribute";
let condition = "defined(_WIN32)";
let value = "__declspec(dllexport)";
}
def : Macro {
- let name = "OFFLOAD_DLLEXPORT";
+ let name = "OL_DLLEXPORT";
let desc = "GCC-specific dllexport storage-class attribute";
let condition = "__GNUC__ >= 4";
let value = "__attribute__ ((visibility (\"default\")))";
@@ -48,22 +48,22 @@ def : Macro {
}
def : Handle {
- let name = "offload_platform_handle_t";
+ let name = "ol_platform_handle_t";
let desc = "Handle of a platform instance";
}
def : Handle {
- let name = "offload_device_handle_t";
+ let name = "ol_device_handle_t";
let desc = "Handle of platform's device object";
}
def : Handle {
- let name = "offload_context_handle_t";
+ let name = "ol_context_handle_t";
let desc = "Handle of context object";
}
def : Enum {
- let name = "offload_errc_t";
+ let name = "ol_errc_t";
let desc = "Defines Return/Error codes";
let etors =[
Etor<"SUCCESS", "Success">,
@@ -87,28 +87,28 @@ def : Enum {
}
def : Struct {
- let name = "offload_error_struct_t";
+ let name = "ol_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<"ol_errc_t", "Code", "The error code">,
StructMember<"const char*", "Details", "String containing error details">
];
}
def : Typedef {
- let name = "offload_result_t";
+ let name = "ol_result_t";
let desc = "Result type returned by all entry points.";
- let value = "const offload_error_struct_t*";
+ let value = "const ol_error_struct_t*";
}
def : Macro {
- let name = "OFFLOAD_RESULT_SUCCESS";
+ let name = "OL_SUCCESS";
let desc = "Success condition";
let value = "NULL";
}
def : Struct {
- let name = "offload_code_location_t";
+ let name = "ol_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">,
@@ -119,18 +119,18 @@ def : Struct {
}
def : Function {
- let name = "offloadInit";
+ let name = "olInit";
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`"
+ "Each call will increment an internal reference count that is decremented by `olShutDown`"
];
let params = [];
let returns = [];
}
def : Function {
- let name = "offloadShutDown";
+ let name = "olShutDown";
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",
diff --git a/offload/new-api/API/Device.td b/offload/new-api/API/Device.td
index 6a931a8172ad70..30c0b71fe7b37c 100644
--- a/offload/new-api/API/Device.td
+++ b/offload/new-api/API/Device.td
@@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//
def : Enum {
- let name = "offload_device_type_t";
+ let name = "ol_device_type_t";
let desc = "Supported device types";
let etors =[
Etor<"DEFAULT", "The default device type as preferred by the runtime">,
@@ -22,12 +22,12 @@ def : Enum {
}
def : Enum {
- let name = "offload_device_info_t";
+ let name = "ol_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<"TYPE", "ol_device_type_t", "type of the device">,
+ TaggedEtor<"PLATFORM", "ol_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">
@@ -35,72 +35,72 @@ def : Enum {
}
def : Function {
- let name = "offloadDeviceGetCount";
+ let name = "olGetDeviceCount";
let desc = "Retrieves the number of available devices within a platform";
let params = [
- Param<"offload_platform_handle_t", "Platform", "handle of the platform instance", PARAM_IN>,
+ Param<"ol_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 = [];
}
def : Function {
- let name = "offloadDeviceGet";
+ let name = "olGetDevice";
let desc = "Retrieves devices within a platform";
let details = [
"Multiple calls to this function will return identical device handles, in the same order.",
];
let params = [
- Param<"offload_platform_handle_t", "Platform", "handle of the platform instance", PARAM_IN>,
+ Param<"ol_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*", "Devices", "Array of device handles. "
+ RangedParam<"ol_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">>
];
let returns = [
- Return<"OFFLOAD_ERRC_INVALID_SIZE", [
+ Return<"OL_ERRC_INVALID_SIZE", [
"`NumEntries == 0`"
]>
];
}
def : Function {
- let name = "offloadDeviceGetInfo";
+ let name = "olGetDeviceInfo";
let desc = "Queries the given property of the device";
let details = [];
let params = [
- 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<"ol_device_handle_t", "Device", "handle of the device instance", PARAM_IN>,
+ Param<"ol_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 "
+ "number of bytes needed to return the info then the OL_ERRC_INVALID_SIZE error is returned and "
"PropValue is not used.", PARAM_OUT, TypeInfo<"PropName" , "PropSize">>
];
let returns = [
- Return<"OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION", [
+ Return<"OL_ERRC_UNSUPPORTED_ENUMERATION", [
"If `PropName` is not supported by the device."
]>,
- Return<"OFFLOAD_ERRC_INVALID_SIZE", [
+ Return<"OL_ERRC_INVALID_SIZE", [
"`PropSize == 0`",
"If `PropSize` is less than the real number of bytes needed to return the info."
]>,
- Return<"OFFLOAD_ERRC_INVALID_DEVICE">
+ Return<"OL_ERRC_INVALID_DEVICE">
];
}
def : Function {
- let name = "offloadDeviceGetInfoSize";
+ let name = "olGetDeviceInfoSize";
let desc = "Returns the storage size of the given device query";
let details = [];
let params = [
- 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<"ol_device_handle_t", "Device", "handle of the device instance", PARAM_IN>,
+ Param<"ol_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", [
+ Return<"OL_ERRC_UNSUPPORTED_ENUMERATION", [
"If `PropName` is not supported by the device."
]>,
- Return<"OFFLOAD_ERRC_INVALID_DEVICE">
+ Return<"OL_ERRC_INVALID_DEVICE">
];
}
diff --git a/offload/new-api/API/Platform.td b/offload/new-api/API/Platform.td
index d2d0bdf176f9f2..03e70cf96ac94f 100644
--- a/offload/new-api/API/Platform.td
+++ b/offload/new-api/API/Platform.td
@@ -10,7 +10,7 @@
//
//===----------------------------------------------------------------------===//
def : Function {
- let name = "offloadPlatformGet";
+ let name = "olGetPlatform";
let desc = "Retrieves all available platforms";
let details = [
"Multiple calls to this function will return identical platforms handles, in the same order.",
@@ -20,21 +20,21 @@ def : Function {
"The number of platforms to be added to Platforms. NumEntries must be "
"greater than zero.",
PARAM_IN>,
- RangedParam<"offload_platform_handle_t*", "Platforms",
+ RangedParam<"ol_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 "
+ "platforms available, then olGetPlatform shall only retrieve that "
"number of platforms.",
PARAM_OUT, Range<"0", "NumEntries">>
];
let returns = [
- Return<"OFFLOAD_ERRC_INVALID_SIZE", [
+ Return<"OL_ERRC_INVALID_SIZE", [
"`NumEntries == 0`"
]>
];
}
def : Function {
- let name = "offloadPlatformGetCount";
+ let name = "olGetPlatformCount";
let desc = "Retrieves the number of available platforms";
let params = [
Param<"uint32_t*",
@@ -45,19 +45,19 @@ def : Function {
}
def : Enum {
- let name = "offload_platform_info_t";
+ let name = "ol_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 native backend of the platform.">
+ TaggedEtor<"BACKEND", "ol_platform_backend_t", "The native backend of the platform.">
];
}
def : Enum {
- let name = "offload_platform_backend_t";
+ let name = "ol_platform_backend_t";
let desc = "Identifies the native backend of the platform";
let etors =[
Etor<"UNKNOWN", "The backend is not recognized">,
@@ -67,46 +67,46 @@ def : Enum {
}
def : Function {
- let name = "offloadPlatformGetInfo";
+ let name = "olGetPlatformInfo";
let desc = "Queries the given property of the platform";
let details = [
- "`offloadPlatformGetInfoSize` can be used to query the storage size "
+ "`olGetPlatformInfoSize` can be used to query the storage size "
"required for the given query."
];
let params = [
- 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<"ol_platform_handle_t", "Platform", "handle of the platform", PARAM_IN>,
+ Param<"ol_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,
+ "then the OL_ERRC_INVALID_SIZE error is returned and pPlatformInfo is not used.", PARAM_OUT,
TypeInfo<"PropName" , "PropSize">>
];
let returns = [
- Return<"OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION", [
+ Return<"OL_ERRC_UNSUPPORTED_ENUMERATION", [
"If `PropName` is not supported by the platform."
]>,
- Return<"OFFLOAD_ERRC_INVALID_SIZE", [
+ Return<"OL_ERRC_INVALID_SIZE", [
"`PropSize == 0`",
"If `PropSize` is less than the real number of bytes needed to return the info."
]>,
- Return<"OFFLOAD_ERRC_INVALID_PLATFORM">
+ Return<"OL_ERRC_INVALID_PLATFORM">
];
}
def : Function {
- let name = "offloadPlatformGetInfoSize";
+ let name = "olGetPlatformInfoSize";
let desc = "Returns the storage size of the given platform query";
let details = [];
let params = [
- 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<"ol_platform_handle_t", "Platform", "handle of the platform", PARAM_IN>,
+ Param<"ol_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", [
+ Return<"OL_ERRC_UNSUPPORTED_ENUMERATION", [
"If `PropName` is not supported by the platform."
]>,
- Return<"OFFLOAD_ERRC_INVALID_PLATFORM">
+ Return<"OL_ERRC_INVALID_PLATFORM">
];
}
diff --git a/offload/new-api/API/README.md b/offload/new-api/API/README.md
index b0b3e5c6620db1..38a055811b2d00 100644
--- a/offload/new-api/API/README.md
+++ b/offload/new-api/API/README.md
@@ -31,7 +31,7 @@ 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.
+* **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. `olGetDeviceInfo`) to return data of an arbitrary type.
#### Return
A return represents a possible return code from the function, and optionally a
@@ -64,7 +64,7 @@ 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`).
+function parameter (e.g. `olGetDeviceInfo`).
All enums automatically get a `<enum_name>_FORCE_UINT32 = 0x7fffffff` value,
which forces the underlying type to be uint32.
diff --git a/offload/new-api/include/offload_api.h b/offload/new-api/include/offload_api.h
index 83dcb41634c3c4..11fcc96625ab8d 100644
--- a/offload/new-api/include/offload_api.h
+++ b/offload/new-api/include/offload_api.h
@@ -18,142 +18,142 @@ extern "C" {
#endif
///////////////////////////////////////////////////////////////////////////////
-#ifndef OFFLOAD_VERSION_MAJOR
+#ifndef OL_VERSION_MAJOR
/// @brief Major version of the Offload API
-#define OFFLOAD_VERSION_MAJOR 0
-#endif // OFFLOAD_VERSION_MAJOR
+#define OL_VERSION_MAJOR 0
+#endif // OL_VERSION_MAJOR
///////////////////////////////////////////////////////////////////////////////
-#ifndef OFFLOAD_VERSION_MINOR
+#ifndef OL_VERSION_MINOR
/// @brief Minor version of the Offload API
-#define OFFLOAD_VERSION_MINOR 0
-#endif // OFFLOAD_VERSION_MINOR
+#define OL_VERSION_MINOR 0
+#endif // OL_VERSION_MINOR
///////////////////////////////////////////////////////////////////////////////
-#ifndef OFFLOAD_VERSION_PATCH
+#ifndef OL_VERSION_PATCH
/// @brief Patch version of the Offload API
-#define OFFLOAD_VERSION_PATCH 1
-#endif // OFFLOAD_VERSION_PATCH
+#define OL_VERSION_PATCH 1
+#endif // OL_VERSION_PATCH
///////////////////////////////////////////////////////////////////////////////
-#ifndef OFFLOAD_APICALL
+#ifndef OL_APICALL
#if defined(_WIN32)
/// @brief Calling convention for all API functions
-#define OFFLOAD_APICALL __cdecl
+#define OL_APICALL __cdecl
#else
-#define OFFLOAD_APICALL
+#define OL_APICALL
#endif // defined(_WIN32)
-#endif // OFFLOAD_APICALL
+#endif // OL_APICALL
///////////////////////////////////////////////////////////////////////////////
-#ifndef OFFLOAD_APIEXPORT
+#ifndef OL_APIEXPORT
#if defined(_WIN32)
/// @brief Microsoft-specific dllexport storage-class attribute
-#define OFFLOAD_APIEXPORT __declspec(dllexport)
+#define OL_APIEXPORT __declspec(dllexport)
#else
-#define OFFLOAD_APIEXPORT
+#define OL_APIEXPORT
#endif // defined(_WIN32)
-#endif // OFFLOAD_APIEXPORT
+#endif // OL_APIEXPORT
///////////////////////////////////////////////////////////////////////////////
-#ifndef OFFLOAD_DLLEXPORT
+#ifndef OL_DLLEXPORT
#if defined(_WIN32)
/// @brief Microsoft-specific dllexport storage-class attribute
-#define OFFLOAD_DLLEXPORT __declspec(dllexport)
+#define OL_DLLEXPORT __declspec(dllexport)
#endif // defined(_WIN32)
-#endif // OFFLOAD_DLLEXPORT
+#endif // OL_DLLEXPORT
///////////////////////////////////////////////////////////////////////////////
-#ifndef OFFLOAD_DLLEXPORT
+#ifndef OL_DLLEXPORT
#if __GNUC__ >= 4
/// @brief GCC-specific dllexport storage-class attribute
-#define OFFLOAD_DLLEXPORT __attribute__((visibility("default")))
+#define OL_DLLEXPORT __attribute__((visibility("default")))
#else
-#define OFFLOAD_DLLEXPORT
+#define OL_DLLEXPORT
#endif // __GNUC__ >= 4
-#endif // OFFLOAD_DLLEXPORT
+#endif // OL_DLLEXPORT
///////////////////////////////////////////////////////////////////////////////
/// @brief Handle of a platform instance
-typedef struct offload_platform_handle_t_ *offload_platform_handle_t;
+typedef struct ol_platform_handle_t_ *ol_platform_handle_t;
///////////////////////////////////////////////////////////////////////////////
/// @brief Handle of platform's device object
-typedef struct offload_device_handle_t_ *offload_device_handle_t;
+typedef struct ol_device_handle_t_ *ol_device_handle_t;
///////////////////////////////////////////////////////////////////////////////
/// @brief Handle of context object
-typedef struct offload_context_handle_t_ *offload_context_handle_t;
+typedef struct ol_context_handle_t_ *ol_context_handle_t;
///////////////////////////////////////////////////////////////////////////////
/// @brief Defines Return/Error codes
-typedef enum offload_errc_t {
+typedef enum ol_errc_t {
/// Success
- OFFLOAD_ERRC_SUCCESS = 0,
+ OL_ERRC_SUCCESS = 0,
/// Invalid Value
- OFFLOAD_ERRC_INVALID_VALUE = 1,
+ OL_ERRC_INVALID_VALUE = 1,
/// Invalid platform
- OFFLOAD_ERRC_INVALID_PLATFORM = 2,
+ OL_ERRC_INVALID_PLATFORM = 2,
/// Device not found
- OFFLOAD_ERRC_DEVICE_NOT_FOUND = 3,
+ OL_ERRC_DEVICE_NOT_FOUND = 3,
/// Invalid device
- OFFLOAD_ERRC_INVALID_DEVICE = 4,
+ OL_ERRC_INVALID_DEVICE = 4,
/// Device hung, reset, was removed, or driver update occurred
- OFFLOAD_ERRC_DEVICE_LOST = 5,
+ OL_ERRC_DEVICE_LOST = 5,
/// plugin is not initialized or specific entry-point is not implemented
- OFFLOAD_ERRC_UNINITIALIZED = 6,
+ OL_ERRC_UNINITIALIZED = 6,
/// Out of resources
- OFFLOAD_ERRC_OUT_OF_RESOURCES = 7,
+ OL_ERRC_OUT_OF_RESOURCES = 7,
/// generic error code for unsupported versions
- OFFLOAD_ERRC_UNSUPPORTED_VERSION = 8,
+ OL_ERRC_UNSUPPORTED_VERSION = 8,
/// generic error code for unsupported features
- OFFLOAD_ERRC_UNSUPPORTED_FEATURE = 9,
+ OL_ERRC_UNSUPPORTED_FEATURE = 9,
/// generic error code for invalid arguments
- OFFLOAD_ERRC_INVALID_ARGUMENT = 10,
+ OL_ERRC_INVALID_ARGUMENT = 10,
/// handle argument is not valid
- OFFLOAD_ERRC_INVALID_NULL_HANDLE = 11,
+ OL_ERRC_INVALID_NULL_HANDLE = 11,
/// pointer argument may not be nullptr
- OFFLOAD_ERRC_INVALID_NULL_POINTER = 12,
+ OL_ERRC_INVALID_NULL_POINTER = 12,
/// invalid size or dimensions (e.g., must not be zero, or is out of bounds)
- OFFLOAD_ERRC_INVALID_SIZE = 13,
+ OL_ERRC_INVALID_SIZE = 13,
/// enumerator argument is not valid
- OFFLOAD_ERRC_INVALID_ENUMERATION = 14,
+ OL_ERRC_INVALID_ENUMERATION = 14,
/// enumerator argument is not supported by the device
- OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION = 15,
+ OL_ERRC_UNSUPPORTED_ENUMERATION = 15,
/// Unknown or internal error
- OFFLOAD_ERRC_UNKNOWN = 16,
+ OL_ERRC_UNKNOWN = 16,
/// @cond
- OFFLOAD_ERRC_FORCE_UINT32 = 0x7fffffff
+ OL_ERRC_FORCE_UINT32 = 0x7fffffff
/// @endcond
-} offload_errc_t;
+} ol_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
+typedef struct ol_error_struct_t {
+ ol_errc_t Code; /// The error code
const char *Details; /// String containing error details
-} offload_error_struct_t;
+} ol_error_struct_t;
///////////////////////////////////////////////////////////////////////////////
/// @brief Result type returned by all entry points.
-typedef const offload_error_struct_t *offload_result_t;
+typedef const ol_error_struct_t *ol_result_t;
///////////////////////////////////////////////////////////////////////////////
-#ifndef OFFLOAD_RESULT_SUCCESS
+#ifndef OL_SUCCESS
/// @brief Success condition
-#define OFFLOAD_RESULT_SUCCESS NULL
-#endif // OFFLOAD_RESULT_SUCCESS
+#define OL_SUCCESS NULL
+#endif // OL_SUCCESS
///////////////////////////////////////////////////////////////////////////////
/// @brief Code location information that can optionally be associated with an
/// API call
-typedef struct offload_code_location_t {
+typedef struct ol_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;
+} ol_code_location_t;
///////////////////////////////////////////////////////////////////////////////
/// @brief Perform initialization of the Offload library and plugins
@@ -161,15 +161,15 @@ typedef struct offload_code_location_t {
/// @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`
+/// decremented by `olShutDown`
///
/// @returns
-/// - ::OFFLOAD_RESULT_SUCCESS
-/// - ::OFFLOAD_ERRC_UNINITIALIZED
-/// - ::OFFLOAD_ERRC_DEVICE_LOST
-/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
-/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadInit();
+/// - ::OL_RESULT_SUCCESS
+/// - ::OL_ERRC_UNINITIALIZED
+/// - ::OL_ERRC_DEVICE_LOST
+/// - ::OL_ERRC_INVALID_NULL_HANDLE
+/// - ::OL_ERRC_INVALID_NULL_POINTER
+OL_APIEXPORT ol_result_t OL_APICALL olInit();
///////////////////////////////////////////////////////////////////////////////
/// @brief Release the resources in use by Offload
@@ -180,12 +180,12 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadInit();
/// - Subsequent API calls made after this are not valid
///
/// @returns
-/// - ::OFFLOAD_RESULT_SUCCESS
-/// - ::OFFLOAD_ERRC_UNINITIALIZED
-/// - ::OFFLOAD_ERRC_DEVICE_LOST
-/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
-/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadShutDown();
+/// - ::OL_RESULT_SUCCESS
+/// - ::OL_ERRC_UNINITIALIZED
+/// - ::OL_ERRC_DEVICE_LOST
+/// - ::OL_ERRC_INVALID_NULL_HANDLE
+/// - ::OL_ERRC_INVALID_NULL_POINTER
+OL_APIEXPORT ol_result_t OL_APICALL olShutDown();
///////////////////////////////////////////////////////////////////////////////
/// @brief Retrieves all available platforms
@@ -195,22 +195,22 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadShutDown();
/// handles, in the same order.
///
/// @returns
-/// - ::OFFLOAD_RESULT_SUCCESS
-/// - ::OFFLOAD_ERRC_UNINITIALIZED
-/// - ::OFFLOAD_ERRC_DEVICE_LOST
-/// - ::OFFLOAD_ERRC_INVALID_SIZE
+/// - ::OL_RESULT_SUCCESS
+/// - ::OL_ERRC_UNINITIALIZED
+/// - ::OL_ERRC_DEVICE_LOST
+/// - ::OL_ERRC_INVALID_SIZE
/// + `NumEntries == 0`
-/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
-/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
+/// - ::OL_ERRC_INVALID_NULL_HANDLE
+/// - ::OL_ERRC_INVALID_NULL_POINTER
/// + `NULL == Platforms`
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGet(
+OL_APIEXPORT ol_result_t OL_APICALL olGetPlatform(
// [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
+ // of platforms available, then olGetPlatform shall only retrieve that
// number of platforms.
- offload_platform_handle_t *Platforms);
+ ol_platform_handle_t *Platforms);
///////////////////////////////////////////////////////////////////////////////
/// @brief Retrieves the number of available platforms
@@ -218,84 +218,83 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGet(
/// @details
///
/// @returns
-/// - ::OFFLOAD_RESULT_SUCCESS
-/// - ::OFFLOAD_ERRC_UNINITIALIZED
-/// - ::OFFLOAD_ERRC_DEVICE_LOST
-/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
-/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
+/// - ::OL_RESULT_SUCCESS
+/// - ::OL_ERRC_UNINITIALIZED
+/// - ::OL_ERRC_DEVICE_LOST
+/// - ::OL_ERRC_INVALID_NULL_HANDLE
+/// - ::OL_ERRC_INVALID_NULL_POINTER
/// + `NULL == NumPlatforms`
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetCount(
+OL_APIEXPORT ol_result_t OL_APICALL olGetPlatformCount(
// [out] returns the total number of platforms available.
uint32_t *NumPlatforms);
///////////////////////////////////////////////////////////////////////////////
/// @brief Supported platform info
-typedef enum offload_platform_info_t {
+typedef enum ol_platform_info_t {
/// [char[]] The string denoting name of the platform. The size of the info
/// needs to be dynamically queried.
- OFFLOAD_PLATFORM_INFO_NAME = 0,
+ OL_PLATFORM_INFO_NAME = 0,
/// [char[]] 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,
+ OL_PLATFORM_INFO_VENDOR_NAME = 1,
/// [char[]] The string denoting the version of the platform. The size of the
/// info needs to be dynamically queried.
- OFFLOAD_PLATFORM_INFO_VERSION = 2,
- /// [offload_platform_backend_t] The native backend of the platform.
- OFFLOAD_PLATFORM_INFO_BACKEND = 3,
+ OL_PLATFORM_INFO_VERSION = 2,
+ /// [ol_platform_backend_t] The native backend of the platform.
+ OL_PLATFORM_INFO_BACKEND = 3,
/// @cond
- OFFLOAD_PLATFORM_INFO_FORCE_UINT32 = 0x7fffffff
+ OL_PLATFORM_INFO_FORCE_UINT32 = 0x7fffffff
/// @endcond
-} offload_platform_info_t;
+} ol_platform_info_t;
///////////////////////////////////////////////////////////////////////////////
/// @brief Identifies the native backend of the platform
-typedef enum offload_platform_backend_t {
+typedef enum ol_platform_backend_t {
/// The backend is not recognized
- OFFLOAD_PLATFORM_BACKEND_UNKNOWN = 0,
+ OL_PLATFORM_BACKEND_UNKNOWN = 0,
/// The backend is CUDA
- OFFLOAD_PLATFORM_BACKEND_CUDA = 1,
+ OL_PLATFORM_BACKEND_CUDA = 1,
/// The backend is AMDGPU
- OFFLOAD_PLATFORM_BACKEND_AMDGPU = 2,
+ OL_PLATFORM_BACKEND_AMDGPU = 2,
/// @cond
- OFFLOAD_PLATFORM_BACKEND_FORCE_UINT32 = 0x7fffffff
+ OL_PLATFORM_BACKEND_FORCE_UINT32 = 0x7fffffff
/// @endcond
-} offload_platform_backend_t;
+} ol_platform_backend_t;
///////////////////////////////////////////////////////////////////////////////
/// @brief Queries the given property of the platform
///
/// @details
-/// - `offloadPlatformGetInfoSize` can be used to query the storage size
-/// required for the given query.
+/// - `olGetPlatformInfoSize` can be used to query the storage size required
+/// for the given query.
///
/// @returns
-/// - ::OFFLOAD_RESULT_SUCCESS
-/// - ::OFFLOAD_ERRC_UNINITIALIZED
-/// - ::OFFLOAD_ERRC_DEVICE_LOST
-/// - ::OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION
+/// - ::OL_RESULT_SUCCESS
+/// - ::OL_ERRC_UNINITIALIZED
+/// - ::OL_ERRC_DEVICE_LOST
+/// - ::OL_ERRC_UNSUPPORTED_ENUMERATION
/// + If `PropName` is not supported by the platform.
-/// - ::OFFLOAD_ERRC_INVALID_SIZE
+/// - ::OL_ERRC_INVALID_SIZE
/// + `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
+/// - ::OL_ERRC_INVALID_PLATFORM
+/// - ::OL_ERRC_INVALID_NULL_HANDLE
/// + `NULL == Platform`
-/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
+/// - ::OL_ERRC_INVALID_NULL_POINTER
/// + `NULL == PropValue`
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfo(
+OL_APIEXPORT ol_result_t OL_APICALL olGetPlatformInfo(
// [in] handle of the platform
- offload_platform_handle_t Platform,
+ ol_platform_handle_t Platform,
// [in] type of the info to retrieve
- offload_platform_info_t PropName,
+ ol_platform_info_t PropName,
// [in] the number of bytes pointed to by pPlatformInfo.
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.
+ // OL_ERRC_INVALID_SIZE error is returned and pPlatformInfo is not used.
void *PropValue);
///////////////////////////////////////////////////////////////////////////////
@@ -304,59 +303,59 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfo(
/// @details
///
/// @returns
-/// - ::OFFLOAD_RESULT_SUCCESS
-/// - ::OFFLOAD_ERRC_UNINITIALIZED
-/// - ::OFFLOAD_ERRC_DEVICE_LOST
-/// - ::OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION
+/// - ::OL_RESULT_SUCCESS
+/// - ::OL_ERRC_UNINITIALIZED
+/// - ::OL_ERRC_DEVICE_LOST
+/// - ::OL_ERRC_UNSUPPORTED_ENUMERATION
/// + If `PropName` is not supported by the platform.
-/// - ::OFFLOAD_ERRC_INVALID_PLATFORM
-/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
+/// - ::OL_ERRC_INVALID_PLATFORM
+/// - ::OL_ERRC_INVALID_NULL_HANDLE
/// + `NULL == Platform`
-/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
+/// - ::OL_ERRC_INVALID_NULL_POINTER
/// + `NULL == PropSizeRet`
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfoSize(
+OL_APIEXPORT ol_result_t OL_APICALL olGetPlatformInfoSize(
// [in] handle of the platform
- offload_platform_handle_t Platform,
+ ol_platform_handle_t Platform,
// [in] type of the info to query
- offload_platform_info_t PropName,
+ ol_platform_info_t PropName,
// [out] pointer to the number of bytes required to store the query
size_t *PropSizeRet);
///////////////////////////////////////////////////////////////////////////////
/// @brief Supported device types
-typedef enum offload_device_type_t {
+typedef enum ol_device_type_t {
/// The default device type as preferred by the runtime
- OFFLOAD_DEVICE_TYPE_DEFAULT = 0,
+ OL_DEVICE_TYPE_DEFAULT = 0,
/// Devices of all types
- OFFLOAD_DEVICE_TYPE_ALL = 1,
+ OL_DEVICE_TYPE_ALL = 1,
/// GPU device type
- OFFLOAD_DEVICE_TYPE_GPU = 2,
+ OL_DEVICE_TYPE_GPU = 2,
/// CPU device type
- OFFLOAD_DEVICE_TYPE_CPU = 3,
+ OL_DEVICE_TYPE_CPU = 3,
/// @cond
- OFFLOAD_DEVICE_TYPE_FORCE_UINT32 = 0x7fffffff
+ OL_DEVICE_TYPE_FORCE_UINT32 = 0x7fffffff
/// @endcond
-} offload_device_type_t;
+} ol_device_type_t;
///////////////////////////////////////////////////////////////////////////////
/// @brief Supported device info
-typedef enum offload_device_info_t {
- /// [offload_device_type_t] type of the device
- OFFLOAD_DEVICE_INFO_TYPE = 0,
- /// [offload_platform_handle_t] the platform associated with the device
- OFFLOAD_DEVICE_INFO_PLATFORM = 1,
+typedef enum ol_device_info_t {
+ /// [ol_device_type_t] type of the device
+ OL_DEVICE_INFO_TYPE = 0,
+ /// [ol_platform_handle_t] the platform associated with the device
+ OL_DEVICE_INFO_PLATFORM = 1,
/// [char[]] Device name
- OFFLOAD_DEVICE_INFO_NAME = 2,
+ OL_DEVICE_INFO_NAME = 2,
/// [char[]] Device vendor
- OFFLOAD_DEVICE_INFO_VENDOR = 3,
+ OL_DEVICE_INFO_VENDOR = 3,
/// [char[]] Driver version
- OFFLOAD_DEVICE_INFO_DRIVER_VERSION = 4,
+ OL_DEVICE_INFO_DRIVER_VERSION = 4,
/// @cond
- OFFLOAD_DEVICE_INFO_FORCE_UINT32 = 0x7fffffff
+ OL_DEVICE_INFO_FORCE_UINT32 = 0x7fffffff
/// @endcond
-} offload_device_info_t;
+} ol_device_info_t;
///////////////////////////////////////////////////////////////////////////////
/// @brief Retrieves the number of available devices within a platform
@@ -364,16 +363,16 @@ typedef enum offload_device_info_t {
/// @details
///
/// @returns
-/// - ::OFFLOAD_RESULT_SUCCESS
-/// - ::OFFLOAD_ERRC_UNINITIALIZED
-/// - ::OFFLOAD_ERRC_DEVICE_LOST
-/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
+/// - ::OL_RESULT_SUCCESS
+/// - ::OL_ERRC_UNINITIALIZED
+/// - ::OL_ERRC_DEVICE_LOST
+/// - ::OL_ERRC_INVALID_NULL_HANDLE
/// + `NULL == Platform`
-/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
+/// - ::OL_ERRC_INVALID_NULL_POINTER
/// + `NULL == NumDevices`
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetCount(
+OL_APIEXPORT ol_result_t OL_APICALL olGetDeviceCount(
// [in] handle of the platform instance
- offload_platform_handle_t Platform,
+ ol_platform_handle_t Platform,
// [out] pointer to the number of devices.
uint32_t *NumDevices);
@@ -385,25 +384,25 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetCount(
/// in the same order.
///
/// @returns
-/// - ::OFFLOAD_RESULT_SUCCESS
-/// - ::OFFLOAD_ERRC_UNINITIALIZED
-/// - ::OFFLOAD_ERRC_DEVICE_LOST
-/// - ::OFFLOAD_ERRC_INVALID_SIZE
+/// - ::OL_RESULT_SUCCESS
+/// - ::OL_ERRC_UNINITIALIZED
+/// - ::OL_ERRC_DEVICE_LOST
+/// - ::OL_ERRC_INVALID_SIZE
/// + `NumEntries == 0`
-/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
+/// - ::OL_ERRC_INVALID_NULL_HANDLE
/// + `NULL == Platform`
-/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
+/// - ::OL_ERRC_INVALID_NULL_POINTER
/// + `NULL == Devices`
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGet(
+OL_APIEXPORT ol_result_t OL_APICALL olGetDevice(
// [in] handle of the platform instance
- offload_platform_handle_t Platform,
+ ol_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 *Devices);
+ ol_device_handle_t *Devices);
///////////////////////////////////////////////////////////////////////////////
/// @brief Queries the given property of the device
@@ -411,30 +410,30 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGet(
/// @details
///
/// @returns
-/// - ::OFFLOAD_RESULT_SUCCESS
-/// - ::OFFLOAD_ERRC_UNINITIALIZED
-/// - ::OFFLOAD_ERRC_DEVICE_LOST
-/// - ::OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION
+/// - ::OL_RESULT_SUCCESS
+/// - ::OL_ERRC_UNINITIALIZED
+/// - ::OL_ERRC_DEVICE_LOST
+/// - ::OL_ERRC_UNSUPPORTED_ENUMERATION
/// + If `PropName` is not supported by the device.
-/// - ::OFFLOAD_ERRC_INVALID_SIZE
+/// - ::OL_ERRC_INVALID_SIZE
/// + `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
+/// - ::OL_ERRC_INVALID_DEVICE
+/// - ::OL_ERRC_INVALID_NULL_HANDLE
/// + `NULL == Device`
-/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
+/// - ::OL_ERRC_INVALID_NULL_POINTER
/// + `NULL == PropValue`
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetInfo(
+OL_APIEXPORT ol_result_t OL_APICALL olGetDeviceInfo(
// [in] handle of the device instance
- offload_device_handle_t Device,
+ ol_device_handle_t Device,
// [in] type of the info to retrieve
- offload_device_info_t PropName,
+ ol_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 PropValue is not used.
+ // OL_ERRC_INVALID_SIZE error is returned and PropValue is not used.
void *PropValue);
///////////////////////////////////////////////////////////////////////////////
@@ -443,181 +442,168 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetInfo(
/// @details
///
/// @returns
-/// - ::OFFLOAD_RESULT_SUCCESS
-/// - ::OFFLOAD_ERRC_UNINITIALIZED
-/// - ::OFFLOAD_ERRC_DEVICE_LOST
-/// - ::OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION
+/// - ::OL_RESULT_SUCCESS
+/// - ::OL_ERRC_UNINITIALIZED
+/// - ::OL_ERRC_DEVICE_LOST
+/// - ::OL_ERRC_UNSUPPORTED_ENUMERATION
/// + If `PropName` is not supported by the device.
-/// - ::OFFLOAD_ERRC_INVALID_DEVICE
-/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
+/// - ::OL_ERRC_INVALID_DEVICE
+/// - ::OL_ERRC_INVALID_NULL_HANDLE
/// + `NULL == Device`
-/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
+/// - ::OL_ERRC_INVALID_NULL_POINTER
/// + `NULL == PropSizeRet`
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetInfoSize(
+OL_APIEXPORT ol_result_t OL_APICALL olGetDeviceInfoSize(
// [in] handle of the device instance
- offload_device_handle_t Device,
+ ol_device_handle_t Device,
// [in] type of the info to retrieve
- offload_device_info_t PropName,
+ ol_device_info_t PropName,
// [out] pointer to the number of bytes required to store the query
size_t *PropSizeRet);
///////////////////////////////////////////////////////////////////////////////
-/// @brief Function parameters for offloadPlatformGet
+/// @brief Function parameters for olGetPlatform
/// @details Each entry is a pointer to the parameter passed to the function;
-typedef struct offload_platform_get_params_t {
+typedef struct ol_get_platform_params_t {
uint32_t *pNumEntries;
- offload_platform_handle_t **pPlatforms;
-} offload_platform_get_params_t;
+ ol_platform_handle_t **pPlatforms;
+} ol_get_platform_params_t;
///////////////////////////////////////////////////////////////////////////////
-/// @brief Function parameters for offloadPlatformGetCount
+/// @brief Function parameters for olGetPlatformCount
/// @details Each entry is a pointer to the parameter passed to the function;
-typedef struct offload_platform_get_count_params_t {
+typedef struct ol_get_platform_count_params_t {
uint32_t **pNumPlatforms;
-} offload_platform_get_count_params_t;
+} ol_get_platform_count_params_t;
///////////////////////////////////////////////////////////////////////////////
-/// @brief Function parameters for offloadPlatformGetInfo
+/// @brief Function parameters for olGetPlatformInfo
/// @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 *pPlatform;
- offload_platform_info_t *pPropName;
+typedef struct ol_get_platform_info_params_t {
+ ol_platform_handle_t *pPlatform;
+ ol_platform_info_t *pPropName;
size_t *pPropSize;
void **pPropValue;
-} offload_platform_get_info_params_t;
+} ol_get_platform_info_params_t;
///////////////////////////////////////////////////////////////////////////////
-/// @brief Function parameters for offloadPlatformGetInfoSize
+/// @brief Function parameters for olGetPlatformInfoSize
/// @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 *pPlatform;
- offload_platform_info_t *pPropName;
+typedef struct ol_get_platform_info_size_params_t {
+ ol_platform_handle_t *pPlatform;
+ ol_platform_info_t *pPropName;
size_t **pPropSizeRet;
-} offload_platform_get_info_size_params_t;
+} ol_get_platform_info_size_params_t;
///////////////////////////////////////////////////////////////////////////////
-/// @brief Function parameters for offloadDeviceGetCount
+/// @brief Function parameters for olGetDeviceCount
/// @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 *pPlatform;
+typedef struct ol_get_device_count_params_t {
+ ol_platform_handle_t *pPlatform;
uint32_t **pNumDevices;
-} offload_device_get_count_params_t;
+} ol_get_device_count_params_t;
///////////////////////////////////////////////////////////////////////////////
-/// @brief Function parameters for offloadDeviceGet
+/// @brief Function parameters for olGetDevice
/// @details Each entry is a pointer to the parameter passed to the function;
-typedef struct offload_device_get_params_t {
- offload_platform_handle_t *pPlatform;
+typedef struct ol_get_device_params_t {
+ ol_platform_handle_t *pPlatform;
uint32_t *pNumEntries;
- offload_device_handle_t **pDevices;
-} offload_device_get_params_t;
+ ol_device_handle_t **pDevices;
+} ol_get_device_params_t;
///////////////////////////////////////////////////////////////////////////////
-/// @brief Function parameters for offloadDeviceGetInfo
+/// @brief Function parameters for olGetDeviceInfo
/// @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 *pDevice;
- offload_device_info_t *pPropName;
+typedef struct ol_get_device_info_params_t {
+ ol_device_handle_t *pDevice;
+ ol_device_info_t *pPropName;
size_t *pPropSize;
void **pPropValue;
-} offload_device_get_info_params_t;
+} ol_get_device_info_params_t;
///////////////////////////////////////////////////////////////////////////////
-/// @brief Function parameters for offloadDeviceGetInfoSize
+/// @brief Function parameters for olGetDeviceInfoSize
/// @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 *pDevice;
- offload_device_info_t *pPropName;
+typedef struct ol_get_device_info_size_params_t {
+ ol_device_handle_t *pDevice;
+ ol_device_info_t *pPropName;
size_t **pPropSizeRet;
-} offload_device_get_info_size_params_t;
+} ol_get_device_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 *CodeLocation);
+/// @brief Variant of olInit that also sets source code location information
+/// @details See also ::olInit
+OL_APIEXPORT ol_result_t OL_APICALL
+olInitWithCodeLoc(ol_code_location_t *CodeLocation);
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Variant of olShutDown that also sets source code location information
+/// @details See also ::olShutDown
+OL_APIEXPORT ol_result_t OL_APICALL
+olShutDownWithCodeLoc(ol_code_location_t *CodeLocation);
///////////////////////////////////////////////////////////////////////////////
-/// @brief Variant of offloadShutDown that also sets source code location
+/// @brief Variant of olGetPlatform that also sets source code location
/// information
-/// @details See also ::offloadShutDown
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
-offloadShutDownWithCodeLoc(offload_code_location_t *CodeLocation);
+/// @details See also ::olGetPlatform
+OL_APIEXPORT ol_result_t OL_APICALL
+olGetPlatformWithCodeLoc(uint32_t NumEntries, ol_platform_handle_t *Platforms,
+ ol_code_location_t *CodeLocation);
///////////////////////////////////////////////////////////////////////////////
-/// @brief Variant of offloadPlatformGet that also sets source code location
+/// @brief Variant of olGetPlatformCount 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 *Platforms,
- offload_code_location_t *CodeLocation);
+/// @details See also ::olGetPlatformCount
+OL_APIEXPORT ol_result_t OL_APICALL olGetPlatformCountWithCodeLoc(
+ uint32_t *NumPlatforms, ol_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 *NumPlatforms,
- offload_code_location_t *CodeLocation);
+/// @brief Variant of olGetPlatformInfo that also sets source code location
+/// information
+/// @details See also ::olGetPlatformInfo
+OL_APIEXPORT ol_result_t OL_APICALL olGetPlatformInfoWithCodeLoc(
+ ol_platform_handle_t Platform, ol_platform_info_t PropName, size_t PropSize,
+ void *PropValue, ol_code_location_t *CodeLocation);
///////////////////////////////////////////////////////////////////////////////
-/// @brief Variant of offloadPlatformGetInfo that also sets source code location
+/// @brief Variant of olGetPlatformInfoSize that also sets source code location
/// information
-/// @details See also ::offloadPlatformGetInfo
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
-offloadPlatformGetInfoWithCodeLoc(offload_platform_handle_t Platform,
- offload_platform_info_t PropName,
- size_t PropSize, void *PropValue,
- offload_code_location_t *CodeLocation);
+/// @details See also ::olGetPlatformInfoSize
+OL_APIEXPORT ol_result_t OL_APICALL olGetPlatformInfoSizeWithCodeLoc(
+ ol_platform_handle_t Platform, ol_platform_info_t PropName,
+ size_t *PropSizeRet, ol_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 Platform,
- offload_platform_info_t PropName,
- size_t *PropSizeRet,
- offload_code_location_t *CodeLocation);
+/// @brief Variant of olGetDeviceCount that also sets source code location
+/// information
+/// @details See also ::olGetDeviceCount
+OL_APIEXPORT ol_result_t OL_APICALL
+olGetDeviceCountWithCodeLoc(ol_platform_handle_t Platform, uint32_t *NumDevices,
+ ol_code_location_t *CodeLocation);
///////////////////////////////////////////////////////////////////////////////
-/// @brief Variant of offloadDeviceGetCount that also sets source code location
+/// @brief Variant of olGetDevice that also sets source code location
/// information
-/// @details See also ::offloadDeviceGetCount
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
-offloadDeviceGetCountWithCodeLoc(offload_platform_handle_t Platform,
- uint32_t *NumDevices,
- offload_code_location_t *CodeLocation);
+/// @details See also ::olGetDevice
+OL_APIEXPORT ol_result_t OL_APICALL olGetDeviceWithCodeLoc(
+ ol_platform_handle_t Platform, uint32_t NumEntries,
+ ol_device_handle_t *Devices, ol_code_location_t *CodeLocation);
///////////////////////////////////////////////////////////////////////////////
-/// @brief Variant of offloadDeviceGet that also sets source code location
+/// @brief Variant of olGetDeviceInfo that also sets source code location
/// information
-/// @details See also ::offloadDeviceGet
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetWithCodeLoc(
- offload_platform_handle_t Platform, uint32_t NumEntries,
- offload_device_handle_t *Devices, offload_code_location_t *CodeLocation);
+/// @details See also ::olGetDeviceInfo
+OL_APIEXPORT ol_result_t OL_APICALL olGetDeviceInfoWithCodeLoc(
+ ol_device_handle_t Device, ol_device_info_t PropName, size_t PropSize,
+ void *PropValue, ol_code_location_t *CodeLocation);
///////////////////////////////////////////////////////////////////////////////
-/// @brief Variant of offloadDeviceGetInfo that also sets source code location
+/// @brief Variant of olGetDeviceInfoSize that also sets source code location
/// information
-/// @details See also ::offloadDeviceGetInfo
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
-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 Device,
- offload_device_info_t PropName,
- size_t *PropSizeRet,
- offload_code_location_t *CodeLocation);
+/// @details See also ::olGetDeviceInfoSize
+OL_APIEXPORT ol_result_t OL_APICALL olGetDeviceInfoSizeWithCodeLoc(
+ ol_device_handle_t Device, ol_device_info_t PropName, size_t *PropSizeRet,
+ ol_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 a21a0ca56cfe6a..49c1c8169615e5 100644
--- a/offload/new-api/include/offload_entry_points.inc
+++ b/offload/new-api/include/offload_entry_points.inc
@@ -7,18 +7,18 @@
//===----------------------------------------------------------------------===//
///////////////////////////////////////////////////////////////////////////////
-offload_impl_result_t offloadInit_val() {
+ol_impl_result_t olInit_val() {
if (true /*enableParameterValidation*/) {
}
- return offloadInit_impl();
+ return olInit_impl();
}
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadInit() {
+OL_APIEXPORT ol_result_t OL_APICALL olInit() {
if (offloadConfig().TracingEnabled) {
- std::cout << "---> offloadInit";
+ std::cout << "---> olInit";
}
- offload_result_t Result = offloadInit_val();
+ ol_result_t Result = olInit_val();
if (offloadConfig().TracingEnabled) {
std::cout << "()";
@@ -29,27 +29,27 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadInit() {
}
return Result;
}
-offload_result_t offloadInitWithCodeLoc(offload_code_location_t *CodeLocation) {
+ol_result_t olInitWithCodeLoc(ol_code_location_t *CodeLocation) {
currentCodeLocation() = CodeLocation;
- offload_result_t Result = offloadInit();
+ ol_result_t Result = olInit();
currentCodeLocation() = nullptr;
return Result;
}
///////////////////////////////////////////////////////////////////////////////
-offload_impl_result_t offloadShutDown_val() {
+ol_impl_result_t olShutDown_val() {
if (true /*enableParameterValidation*/) {
}
- return offloadShutDown_impl();
+ return olShutDown_impl();
}
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadShutDown() {
+OL_APIEXPORT ol_result_t OL_APICALL olShutDown() {
if (offloadConfig().TracingEnabled) {
- std::cout << "---> offloadShutDown";
+ std::cout << "---> olShutDown";
}
- offload_result_t Result = offloadShutDown_val();
+ ol_result_t Result = olShutDown_val();
if (offloadConfig().TracingEnabled) {
std::cout << "()";
@@ -60,41 +60,39 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadShutDown() {
}
return Result;
}
-offload_result_t
-offloadShutDownWithCodeLoc(offload_code_location_t *CodeLocation) {
+ol_result_t olShutDownWithCodeLoc(ol_code_location_t *CodeLocation) {
currentCodeLocation() = CodeLocation;
- offload_result_t Result = offloadShutDown();
+ ol_result_t Result = olShutDown();
currentCodeLocation() = nullptr;
return Result;
}
///////////////////////////////////////////////////////////////////////////////
-offload_impl_result_t
-offloadPlatformGet_val(uint32_t NumEntries,
- offload_platform_handle_t *Platforms) {
+ol_impl_result_t olGetPlatform_val(uint32_t NumEntries,
+ ol_platform_handle_t *Platforms) {
if (true /*enableParameterValidation*/) {
if (NumEntries == 0) {
- return OFFLOAD_ERRC_INVALID_SIZE;
+ return OL_ERRC_INVALID_SIZE;
}
if (NULL == Platforms) {
- return OFFLOAD_ERRC_INVALID_NULL_POINTER;
+ return OL_ERRC_INVALID_NULL_POINTER;
}
}
- return offloadPlatformGet_impl(NumEntries, Platforms);
+ return olGetPlatform_impl(NumEntries, Platforms);
}
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
-offloadPlatformGet(uint32_t NumEntries, offload_platform_handle_t *Platforms) {
+OL_APIEXPORT ol_result_t OL_APICALL
+olGetPlatform(uint32_t NumEntries, ol_platform_handle_t *Platforms) {
if (offloadConfig().TracingEnabled) {
- std::cout << "---> offloadPlatformGet";
+ std::cout << "---> olGetPlatform";
}
- offload_result_t Result = offloadPlatformGet_val(NumEntries, Platforms);
+ ol_result_t Result = olGetPlatform_val(NumEntries, Platforms);
if (offloadConfig().TracingEnabled) {
- offload_platform_get_params_t Params = {&NumEntries, &Platforms};
+ ol_get_platform_params_t Params = {&NumEntries, &Platforms};
std::cout << "(" << &Params << ")";
std::cout << "-> " << Result << "\n";
if (Result && Result->Details) {
@@ -103,37 +101,35 @@ offloadPlatformGet(uint32_t NumEntries, offload_platform_handle_t *Platforms) {
}
return Result;
}
-offload_result_t
-offloadPlatformGetWithCodeLoc(uint32_t NumEntries,
- offload_platform_handle_t *Platforms,
- offload_code_location_t *CodeLocation) {
+ol_result_t olGetPlatformWithCodeLoc(uint32_t NumEntries,
+ ol_platform_handle_t *Platforms,
+ ol_code_location_t *CodeLocation) {
currentCodeLocation() = CodeLocation;
- offload_result_t Result = offloadPlatformGet(NumEntries, Platforms);
+ ol_result_t Result = olGetPlatform(NumEntries, Platforms);
currentCodeLocation() = nullptr;
return Result;
}
///////////////////////////////////////////////////////////////////////////////
-offload_impl_result_t offloadPlatformGetCount_val(uint32_t *NumPlatforms) {
+ol_impl_result_t olGetPlatformCount_val(uint32_t *NumPlatforms) {
if (true /*enableParameterValidation*/) {
if (NULL == NumPlatforms) {
- return OFFLOAD_ERRC_INVALID_NULL_POINTER;
+ return OL_ERRC_INVALID_NULL_POINTER;
}
}
- return offloadPlatformGetCount_impl(NumPlatforms);
+ return olGetPlatformCount_impl(NumPlatforms);
}
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
-offloadPlatformGetCount(uint32_t *NumPlatforms) {
+OL_APIEXPORT ol_result_t OL_APICALL olGetPlatformCount(uint32_t *NumPlatforms) {
if (offloadConfig().TracingEnabled) {
- std::cout << "---> offloadPlatformGetCount";
+ std::cout << "---> olGetPlatformCount";
}
- offload_result_t Result = offloadPlatformGetCount_val(NumPlatforms);
+ ol_result_t Result = olGetPlatformCount_val(NumPlatforms);
if (offloadConfig().TracingEnabled) {
- offload_platform_get_count_params_t Params = {&NumPlatforms};
+ ol_get_platform_count_params_t Params = {&NumPlatforms};
std::cout << "(" << &Params << ")";
std::cout << "-> " << Result << "\n";
if (Result && Result->Details) {
@@ -142,50 +138,48 @@ offloadPlatformGetCount(uint32_t *NumPlatforms) {
}
return Result;
}
-offload_result_t
-offloadPlatformGetCountWithCodeLoc(uint32_t *NumPlatforms,
- offload_code_location_t *CodeLocation) {
+ol_result_t olGetPlatformCountWithCodeLoc(uint32_t *NumPlatforms,
+ ol_code_location_t *CodeLocation) {
currentCodeLocation() = CodeLocation;
- offload_result_t Result = offloadPlatformGetCount(NumPlatforms);
+ ol_result_t Result = olGetPlatformCount(NumPlatforms);
currentCodeLocation() = nullptr;
return Result;
}
///////////////////////////////////////////////////////////////////////////////
-offload_impl_result_t
-offloadPlatformGetInfo_val(offload_platform_handle_t Platform,
- offload_platform_info_t PropName, size_t PropSize,
- void *PropValue) {
+ol_impl_result_t olGetPlatformInfo_val(ol_platform_handle_t Platform,
+ ol_platform_info_t PropName,
+ size_t PropSize, void *PropValue) {
if (true /*enableParameterValidation*/) {
if (PropSize == 0) {
- return OFFLOAD_ERRC_INVALID_SIZE;
+ return OL_ERRC_INVALID_SIZE;
}
if (NULL == Platform) {
- return OFFLOAD_ERRC_INVALID_NULL_HANDLE;
+ return OL_ERRC_INVALID_NULL_HANDLE;
}
if (NULL == PropValue) {
- return OFFLOAD_ERRC_INVALID_NULL_POINTER;
+ return OL_ERRC_INVALID_NULL_POINTER;
}
}
- return offloadPlatformGetInfo_impl(Platform, PropName, PropSize, PropValue);
+ return olGetPlatformInfo_impl(Platform, PropName, PropSize, PropValue);
}
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfo(
- offload_platform_handle_t Platform, offload_platform_info_t PropName,
- size_t PropSize, void *PropValue) {
+OL_APIEXPORT ol_result_t OL_APICALL
+olGetPlatformInfo(ol_platform_handle_t Platform, ol_platform_info_t PropName,
+ size_t PropSize, void *PropValue) {
if (offloadConfig().TracingEnabled) {
- std::cout << "---> offloadPlatformGetInfo";
+ std::cout << "---> olGetPlatformInfo";
}
- offload_result_t Result =
- offloadPlatformGetInfo_val(Platform, PropName, PropSize, PropValue);
+ ol_result_t Result =
+ olGetPlatformInfo_val(Platform, PropName, PropSize, PropValue);
if (offloadConfig().TracingEnabled) {
- offload_platform_get_info_params_t Params = {&Platform, &PropName,
- &PropSize, &PropValue};
+ ol_get_platform_info_params_t Params = {&Platform, &PropName, &PropSize,
+ &PropValue};
std::cout << "(" << &Params << ")";
std::cout << "-> " << Result << "\n";
if (Result && Result->Details) {
@@ -194,47 +188,47 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfo(
}
return Result;
}
-offload_result_t offloadPlatformGetInfoWithCodeLoc(
- offload_platform_handle_t Platform, offload_platform_info_t PropName,
- size_t PropSize, void *PropValue, offload_code_location_t *CodeLocation) {
+ol_result_t olGetPlatformInfoWithCodeLoc(ol_platform_handle_t Platform,
+ ol_platform_info_t PropName,
+ size_t PropSize, void *PropValue,
+ ol_code_location_t *CodeLocation) {
currentCodeLocation() = CodeLocation;
- offload_result_t Result =
- offloadPlatformGetInfo(Platform, PropName, PropSize, PropValue);
+ ol_result_t Result =
+ olGetPlatformInfo(Platform, PropName, PropSize, PropValue);
currentCodeLocation() = nullptr;
return Result;
}
///////////////////////////////////////////////////////////////////////////////
-offload_impl_result_t
-offloadPlatformGetInfoSize_val(offload_platform_handle_t Platform,
- offload_platform_info_t PropName,
- size_t *PropSizeRet) {
+ol_impl_result_t olGetPlatformInfoSize_val(ol_platform_handle_t Platform,
+ ol_platform_info_t PropName,
+ size_t *PropSizeRet) {
if (true /*enableParameterValidation*/) {
if (NULL == Platform) {
- return OFFLOAD_ERRC_INVALID_NULL_HANDLE;
+ return OL_ERRC_INVALID_NULL_HANDLE;
}
if (NULL == PropSizeRet) {
- return OFFLOAD_ERRC_INVALID_NULL_POINTER;
+ return OL_ERRC_INVALID_NULL_POINTER;
}
}
- return offloadPlatformGetInfoSize_impl(Platform, PropName, PropSizeRet);
+ return olGetPlatformInfoSize_impl(Platform, PropName, PropSizeRet);
}
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfoSize(
- offload_platform_handle_t Platform, offload_platform_info_t PropName,
- size_t *PropSizeRet) {
+OL_APIEXPORT ol_result_t OL_APICALL
+olGetPlatformInfoSize(ol_platform_handle_t Platform,
+ ol_platform_info_t PropName, size_t *PropSizeRet) {
if (offloadConfig().TracingEnabled) {
- std::cout << "---> offloadPlatformGetInfoSize";
+ std::cout << "---> olGetPlatformInfoSize";
}
- offload_result_t Result =
- offloadPlatformGetInfoSize_val(Platform, PropName, PropSizeRet);
+ ol_result_t Result =
+ olGetPlatformInfoSize_val(Platform, PropName, PropSizeRet);
if (offloadConfig().TracingEnabled) {
- offload_platform_get_info_size_params_t Params = {&Platform, &PropName,
- &PropSizeRet};
+ ol_get_platform_info_size_params_t Params = {&Platform, &PropName,
+ &PropSizeRet};
std::cout << "(" << &Params << ")";
std::cout << "-> " << Result << "\n";
if (Result && Result->Details) {
@@ -243,43 +237,42 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfoSize(
}
return Result;
}
-offload_result_t offloadPlatformGetInfoSizeWithCodeLoc(
- offload_platform_handle_t Platform, offload_platform_info_t PropName,
- size_t *PropSizeRet, offload_code_location_t *CodeLocation) {
+ol_result_t olGetPlatformInfoSizeWithCodeLoc(ol_platform_handle_t Platform,
+ ol_platform_info_t PropName,
+ size_t *PropSizeRet,
+ ol_code_location_t *CodeLocation) {
currentCodeLocation() = CodeLocation;
- offload_result_t Result =
- offloadPlatformGetInfoSize(Platform, PropName, PropSizeRet);
+ ol_result_t Result = olGetPlatformInfoSize(Platform, PropName, PropSizeRet);
currentCodeLocation() = nullptr;
return Result;
}
///////////////////////////////////////////////////////////////////////////////
-offload_impl_result_t
-offloadDeviceGetCount_val(offload_platform_handle_t Platform,
- uint32_t *NumDevices) {
+ol_impl_result_t olGetDeviceCount_val(ol_platform_handle_t Platform,
+ uint32_t *NumDevices) {
if (true /*enableParameterValidation*/) {
if (NULL == Platform) {
- return OFFLOAD_ERRC_INVALID_NULL_HANDLE;
+ return OL_ERRC_INVALID_NULL_HANDLE;
}
if (NULL == NumDevices) {
- return OFFLOAD_ERRC_INVALID_NULL_POINTER;
+ return OL_ERRC_INVALID_NULL_POINTER;
}
}
- return offloadDeviceGetCount_impl(Platform, NumDevices);
+ return olGetDeviceCount_impl(Platform, NumDevices);
}
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetCount(
- offload_platform_handle_t Platform, uint32_t *NumDevices) {
+OL_APIEXPORT ol_result_t OL_APICALL
+olGetDeviceCount(ol_platform_handle_t Platform, uint32_t *NumDevices) {
if (offloadConfig().TracingEnabled) {
- std::cout << "---> offloadDeviceGetCount";
+ std::cout << "---> olGetDeviceCount";
}
- offload_result_t Result = offloadDeviceGetCount_val(Platform, NumDevices);
+ ol_result_t Result = olGetDeviceCount_val(Platform, NumDevices);
if (offloadConfig().TracingEnabled) {
- offload_device_get_count_params_t Params = {&Platform, &NumDevices};
+ ol_get_device_count_params_t Params = {&Platform, &NumDevices};
std::cout << "(" << &Params << ")";
std::cout << "-> " << Result << "\n";
if (Result && Result->Details) {
@@ -288,48 +281,47 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetCount(
}
return Result;
}
-offload_result_t
-offloadDeviceGetCountWithCodeLoc(offload_platform_handle_t Platform,
- uint32_t *NumDevices,
- offload_code_location_t *CodeLocation) {
+ol_result_t olGetDeviceCountWithCodeLoc(ol_platform_handle_t Platform,
+ uint32_t *NumDevices,
+ ol_code_location_t *CodeLocation) {
currentCodeLocation() = CodeLocation;
- offload_result_t Result = offloadDeviceGetCount(Platform, NumDevices);
+ ol_result_t Result = olGetDeviceCount(Platform, NumDevices);
currentCodeLocation() = nullptr;
return Result;
}
///////////////////////////////////////////////////////////////////////////////
-offload_impl_result_t offloadDeviceGet_val(offload_platform_handle_t Platform,
- uint32_t NumEntries,
- offload_device_handle_t *Devices) {
+ol_impl_result_t olGetDevice_val(ol_platform_handle_t Platform,
+ uint32_t NumEntries,
+ ol_device_handle_t *Devices) {
if (true /*enableParameterValidation*/) {
if (NumEntries == 0) {
- return OFFLOAD_ERRC_INVALID_SIZE;
+ return OL_ERRC_INVALID_SIZE;
}
if (NULL == Platform) {
- return OFFLOAD_ERRC_INVALID_NULL_HANDLE;
+ return OL_ERRC_INVALID_NULL_HANDLE;
}
if (NULL == Devices) {
- return OFFLOAD_ERRC_INVALID_NULL_POINTER;
+ return OL_ERRC_INVALID_NULL_POINTER;
}
}
- return offloadDeviceGet_impl(Platform, NumEntries, Devices);
+ return olGetDevice_impl(Platform, NumEntries, Devices);
}
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
-offloadDeviceGet(offload_platform_handle_t Platform, uint32_t NumEntries,
- offload_device_handle_t *Devices) {
+OL_APIEXPORT ol_result_t OL_APICALL olGetDevice(ol_platform_handle_t Platform,
+ uint32_t NumEntries,
+ ol_device_handle_t *Devices) {
if (offloadConfig().TracingEnabled) {
- std::cout << "---> offloadDeviceGet";
+ std::cout << "---> olGetDevice";
}
- offload_result_t Result = offloadDeviceGet_val(Platform, NumEntries, Devices);
+ ol_result_t Result = olGetDevice_val(Platform, NumEntries, Devices);
if (offloadConfig().TracingEnabled) {
- offload_device_get_params_t Params = {&Platform, &NumEntries, &Devices};
+ ol_get_device_params_t Params = {&Platform, &NumEntries, &Devices};
std::cout << "(" << &Params << ")";
std::cout << "-> " << Result << "\n";
if (Result && Result->Details) {
@@ -338,50 +330,51 @@ offloadDeviceGet(offload_platform_handle_t Platform, uint32_t NumEntries,
}
return Result;
}
-offload_result_t offloadDeviceGetWithCodeLoc(
- offload_platform_handle_t Platform, uint32_t NumEntries,
- offload_device_handle_t *Devices, offload_code_location_t *CodeLocation) {
+ol_result_t olGetDeviceWithCodeLoc(ol_platform_handle_t Platform,
+ uint32_t NumEntries,
+ ol_device_handle_t *Devices,
+ ol_code_location_t *CodeLocation) {
currentCodeLocation() = CodeLocation;
- offload_result_t Result = offloadDeviceGet(Platform, NumEntries, Devices);
+ ol_result_t Result = olGetDevice(Platform, NumEntries, Devices);
currentCodeLocation() = nullptr;
return Result;
}
///////////////////////////////////////////////////////////////////////////////
-offload_impl_result_t offloadDeviceGetInfo_val(offload_device_handle_t Device,
- offload_device_info_t PropName,
- size_t PropSize,
- void *PropValue) {
+ol_impl_result_t olGetDeviceInfo_val(ol_device_handle_t Device,
+ ol_device_info_t PropName, size_t PropSize,
+ void *PropValue) {
if (true /*enableParameterValidation*/) {
if (PropSize == 0) {
- return OFFLOAD_ERRC_INVALID_SIZE;
+ return OL_ERRC_INVALID_SIZE;
}
if (NULL == Device) {
- return OFFLOAD_ERRC_INVALID_NULL_HANDLE;
+ return OL_ERRC_INVALID_NULL_HANDLE;
}
if (NULL == PropValue) {
- return OFFLOAD_ERRC_INVALID_NULL_POINTER;
+ return OL_ERRC_INVALID_NULL_POINTER;
}
}
- return offloadDeviceGetInfo_impl(Device, PropName, PropSize, PropValue);
+ return olGetDeviceInfo_impl(Device, PropName, PropSize, PropValue);
}
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetInfo(
- offload_device_handle_t Device, offload_device_info_t PropName,
- size_t PropSize, void *PropValue) {
+OL_APIEXPORT ol_result_t OL_APICALL olGetDeviceInfo(ol_device_handle_t Device,
+ ol_device_info_t PropName,
+ size_t PropSize,
+ void *PropValue) {
if (offloadConfig().TracingEnabled) {
- std::cout << "---> offloadDeviceGetInfo";
+ std::cout << "---> olGetDeviceInfo";
}
- offload_result_t Result =
- offloadDeviceGetInfo_val(Device, PropName, PropSize, PropValue);
+ ol_result_t Result =
+ olGetDeviceInfo_val(Device, PropName, PropSize, PropValue);
if (offloadConfig().TracingEnabled) {
- offload_device_get_info_params_t Params = {&Device, &PropName, &PropSize,
- &PropValue};
+ ol_get_device_info_params_t Params = {&Device, &PropName, &PropSize,
+ &PropValue};
std::cout << "(" << &Params << ")";
std::cout << "-> " << Result << "\n";
if (Result && Result->Details) {
@@ -390,47 +383,44 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetInfo(
}
return Result;
}
-offload_result_t offloadDeviceGetInfoWithCodeLoc(
- offload_device_handle_t Device, offload_device_info_t PropName,
- size_t PropSize, void *PropValue, offload_code_location_t *CodeLocation) {
+ol_result_t olGetDeviceInfoWithCodeLoc(ol_device_handle_t Device,
+ ol_device_info_t PropName,
+ size_t PropSize, void *PropValue,
+ ol_code_location_t *CodeLocation) {
currentCodeLocation() = CodeLocation;
- offload_result_t Result =
- offloadDeviceGetInfo(Device, PropName, PropSize, PropValue);
+ ol_result_t Result = olGetDeviceInfo(Device, PropName, PropSize, PropValue);
currentCodeLocation() = nullptr;
return Result;
}
///////////////////////////////////////////////////////////////////////////////
-offload_impl_result_t
-offloadDeviceGetInfoSize_val(offload_device_handle_t Device,
- offload_device_info_t PropName,
- size_t *PropSizeRet) {
+ol_impl_result_t olGetDeviceInfoSize_val(ol_device_handle_t Device,
+ ol_device_info_t PropName,
+ size_t *PropSizeRet) {
if (true /*enableParameterValidation*/) {
if (NULL == Device) {
- return OFFLOAD_ERRC_INVALID_NULL_HANDLE;
+ return OL_ERRC_INVALID_NULL_HANDLE;
}
if (NULL == PropSizeRet) {
- return OFFLOAD_ERRC_INVALID_NULL_POINTER;
+ return OL_ERRC_INVALID_NULL_POINTER;
}
}
- return offloadDeviceGetInfoSize_impl(Device, PropName, PropSizeRet);
+ return olGetDeviceInfoSize_impl(Device, PropName, PropSizeRet);
}
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
-offloadDeviceGetInfoSize(offload_device_handle_t Device,
- offload_device_info_t PropName, size_t *PropSizeRet) {
+OL_APIEXPORT ol_result_t OL_APICALL olGetDeviceInfoSize(
+ ol_device_handle_t Device, ol_device_info_t PropName, size_t *PropSizeRet) {
if (offloadConfig().TracingEnabled) {
- std::cout << "---> offloadDeviceGetInfoSize";
+ std::cout << "---> olGetDeviceInfoSize";
}
- offload_result_t Result =
- offloadDeviceGetInfoSize_val(Device, PropName, PropSizeRet);
+ ol_result_t Result = olGetDeviceInfoSize_val(Device, PropName, PropSizeRet);
if (offloadConfig().TracingEnabled) {
- offload_device_get_info_size_params_t Params = {&Device, &PropName,
- &PropSizeRet};
+ ol_get_device_info_size_params_t Params = {&Device, &PropName,
+ &PropSizeRet};
std::cout << "(" << &Params << ")";
std::cout << "-> " << Result << "\n";
if (Result && Result->Details) {
@@ -439,12 +429,12 @@ offloadDeviceGetInfoSize(offload_device_handle_t Device,
}
return Result;
}
-offload_result_t offloadDeviceGetInfoSizeWithCodeLoc(
- offload_device_handle_t Device, offload_device_info_t PropName,
- size_t *PropSizeRet, offload_code_location_t *CodeLocation) {
+ol_result_t olGetDeviceInfoSizeWithCodeLoc(ol_device_handle_t Device,
+ ol_device_info_t PropName,
+ size_t *PropSizeRet,
+ ol_code_location_t *CodeLocation) {
currentCodeLocation() = CodeLocation;
- offload_result_t Result =
- offloadDeviceGetInfoSize(Device, PropName, PropSizeRet);
+ ol_result_t Result = olGetDeviceInfoSize(Device, PropName, PropSizeRet);
currentCodeLocation() = nullptr;
return Result;
diff --git a/offload/new-api/include/offload_exports b/offload/new-api/include/offload_exports
index 1940eeed720df6..a07a4a4bc2029a 100644
--- a/offload/new-api/include/offload_exports
+++ b/offload/new-api/include/offload_exports
@@ -1,25 +1,25 @@
VERS1.0 {
global:
- offloadInit;
- offloadShutDown;
- offloadPlatformGet;
- offloadPlatformGetCount;
- offloadPlatformGetInfo;
- offloadPlatformGetInfoSize;
- offloadDeviceGetCount;
- offloadDeviceGet;
- offloadDeviceGetInfo;
- offloadDeviceGetInfoSize;
- offloadInitWithCodeLoc;
- offloadShutDownWithCodeLoc;
- offloadPlatformGetWithCodeLoc;
- offloadPlatformGetCountWithCodeLoc;
- offloadPlatformGetInfoWithCodeLoc;
- offloadPlatformGetInfoSizeWithCodeLoc;
- offloadDeviceGetCountWithCodeLoc;
- offloadDeviceGetWithCodeLoc;
- offloadDeviceGetInfoWithCodeLoc;
- offloadDeviceGetInfoSizeWithCodeLoc;
+ olInit;
+ olShutDown;
+ olGetPlatform;
+ olGetPlatformCount;
+ olGetPlatformInfo;
+ olGetPlatformInfoSize;
+ olGetDeviceCount;
+ olGetDevice;
+ olGetDeviceInfo;
+ olGetDeviceInfoSize;
+ olInitWithCodeLoc;
+ olShutDownWithCodeLoc;
+ olGetPlatformWithCodeLoc;
+ olGetPlatformCountWithCodeLoc;
+ olGetPlatformInfoWithCodeLoc;
+ olGetPlatformInfoSizeWithCodeLoc;
+ olGetDeviceCountWithCodeLoc;
+ olGetDeviceWithCodeLoc;
+ olGetDeviceInfoWithCodeLoc;
+ olGetDeviceInfoSizeWithCodeLoc;
local:
*;
};
diff --git a/offload/new-api/include/offload_funcs.inc b/offload/new-api/include/offload_funcs.inc
index afa4c11e46977a..48115493c790f4 100644
--- a/offload/new-api/include/offload_funcs.inc
+++ b/offload/new-api/include/offload_funcs.inc
@@ -10,25 +10,25 @@
#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)
-OFFLOAD_FUNC(offloadInitWithCodeLoc)
-OFFLOAD_FUNC(offloadShutDownWithCodeLoc)
-OFFLOAD_FUNC(offloadPlatformGetWithCodeLoc)
-OFFLOAD_FUNC(offloadPlatformGetCountWithCodeLoc)
-OFFLOAD_FUNC(offloadPlatformGetInfoWithCodeLoc)
-OFFLOAD_FUNC(offloadPlatformGetInfoSizeWithCodeLoc)
-OFFLOAD_FUNC(offloadDeviceGetCountWithCodeLoc)
-OFFLOAD_FUNC(offloadDeviceGetWithCodeLoc)
-OFFLOAD_FUNC(offloadDeviceGetInfoWithCodeLoc)
-OFFLOAD_FUNC(offloadDeviceGetInfoSizeWithCodeLoc)
+OFFLOAD_FUNC(olInit)
+OFFLOAD_FUNC(olShutDown)
+OFFLOAD_FUNC(olGetPlatform)
+OFFLOAD_FUNC(olGetPlatformCount)
+OFFLOAD_FUNC(olGetPlatformInfo)
+OFFLOAD_FUNC(olGetPlatformInfoSize)
+OFFLOAD_FUNC(olGetDeviceCount)
+OFFLOAD_FUNC(olGetDevice)
+OFFLOAD_FUNC(olGetDeviceInfo)
+OFFLOAD_FUNC(olGetDeviceInfoSize)
+OFFLOAD_FUNC(olInitWithCodeLoc)
+OFFLOAD_FUNC(olShutDownWithCodeLoc)
+OFFLOAD_FUNC(olGetPlatformWithCodeLoc)
+OFFLOAD_FUNC(olGetPlatformCountWithCodeLoc)
+OFFLOAD_FUNC(olGetPlatformInfoWithCodeLoc)
+OFFLOAD_FUNC(olGetPlatformInfoSizeWithCodeLoc)
+OFFLOAD_FUNC(olGetDeviceCountWithCodeLoc)
+OFFLOAD_FUNC(olGetDeviceWithCodeLoc)
+OFFLOAD_FUNC(olGetDeviceInfoWithCodeLoc)
+OFFLOAD_FUNC(olGetDeviceInfoSizeWithCodeLoc)
#undef OFFLOAD_FUNC
diff --git a/offload/new-api/include/offload_impl.hpp b/offload/new-api/include/offload_impl.hpp
index 0774f8ea5e8ef2..80966ccf234f06 100644
--- a/offload/new-api/include/offload_impl.hpp
+++ b/offload/new-api/include/offload_impl.hpp
@@ -34,7 +34,7 @@ llvm::StringSet<> &errorStrs();
// 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>;
+using ErrPtrT = std::unique_ptr<ol_error_struct_t>;
struct ErrPtrEqual {
bool operator()(const ErrPtrT &lhs, const ErrPtrT &rhs) const {
if (!lhs && !rhs) {
@@ -66,29 +66,29 @@ struct ErrPtrHash {
using ErrSetT = std::unordered_set<ErrPtrT, ErrPtrHash, ErrPtrEqual>;
ErrSetT &errors();
-struct offload_impl_result_t {
- offload_impl_result_t(std::nullptr_t) : Result(OFFLOAD_RESULT_SUCCESS) {}
- offload_impl_result_t(offload_errc_t Code) {
- if (Code == OFFLOAD_ERRC_SUCCESS) {
+struct ol_impl_result_t {
+ ol_impl_result_t(std::nullptr_t) : Result(OL_SUCCESS) {}
+ ol_impl_result_t(ol_errc_t Code) {
+ if (Code == OL_ERRC_SUCCESS) {
Result = nullptr;
} else {
- auto Err = std::unique_ptr<offload_error_struct_t>(
- new offload_error_struct_t{Code, nullptr});
+ auto Err = std::unique_ptr<ol_error_struct_t>(
+ new ol_error_struct_t{Code, nullptr});
Result = errors().emplace(std::move(Err)).first->get();
}
}
- offload_impl_result_t(offload_errc_t Code, llvm::StringRef Details) {
- assert(Code != OFFLOAD_ERRC_SUCCESS);
+ ol_impl_result_t(ol_errc_t Code, llvm::StringRef Details) {
+ assert(Code != OL_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});
+ auto Err = std::unique_ptr<ol_error_struct_t>(
+ new ol_error_struct_t{Code, DetailsStr});
Result = errors().emplace(std::move(Err)).first->get();
}
- operator offload_result_t() { return Result; }
+ operator ol_result_t() { return Result; }
private:
- offload_result_t Result;
+ ol_result_t Result;
};
diff --git a/offload/new-api/include/offload_impl_func_decls.inc b/offload/new-api/include/offload_impl_func_decls.inc
index c56a393ae492a3..5b26b2653a05d9 100644
--- a/offload/new-api/include/offload_impl_func_decls.inc
+++ b/offload/new-api/include/offload_impl_func_decls.inc
@@ -5,40 +5,34 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
-offload_impl_result_t offloadInit_impl();
+ol_impl_result_t olInit_impl();
-offload_impl_result_t offloadShutDown_impl();
+ol_impl_result_t olShutDown_impl();
-offload_impl_result_t
-offloadPlatformGet_impl(uint32_t NumEntries,
- offload_platform_handle_t *Platforms);
+ol_impl_result_t olGetPlatform_impl(uint32_t NumEntries,
+ ol_platform_handle_t *Platforms);
-offload_impl_result_t offloadPlatformGetCount_impl(uint32_t *NumPlatforms);
+ol_impl_result_t olGetPlatformCount_impl(uint32_t *NumPlatforms);
-offload_impl_result_t
-offloadPlatformGetInfo_impl(offload_platform_handle_t Platform,
- offload_platform_info_t PropName, size_t PropSize,
- void *PropValue);
+ol_impl_result_t olGetPlatformInfo_impl(ol_platform_handle_t Platform,
+ ol_platform_info_t PropName,
+ size_t PropSize, void *PropValue);
-offload_impl_result_t
-offloadPlatformGetInfoSize_impl(offload_platform_handle_t Platform,
- offload_platform_info_t PropName,
- size_t *PropSizeRet);
+ol_impl_result_t olGetPlatformInfoSize_impl(ol_platform_handle_t Platform,
+ ol_platform_info_t PropName,
+ size_t *PropSizeRet);
-offload_impl_result_t
-offloadDeviceGetCount_impl(offload_platform_handle_t Platform,
- uint32_t *NumDevices);
+ol_impl_result_t olGetDeviceCount_impl(ol_platform_handle_t Platform,
+ uint32_t *NumDevices);
-offload_impl_result_t offloadDeviceGet_impl(offload_platform_handle_t Platform,
- uint32_t NumEntries,
- offload_device_handle_t *Devices);
+ol_impl_result_t olGetDevice_impl(ol_platform_handle_t Platform,
+ uint32_t NumEntries,
+ ol_device_handle_t *Devices);
-offload_impl_result_t offloadDeviceGetInfo_impl(offload_device_handle_t Device,
- offload_device_info_t PropName,
- size_t PropSize,
- void *PropValue);
+ol_impl_result_t olGetDeviceInfo_impl(ol_device_handle_t Device,
+ ol_device_info_t PropName,
+ size_t PropSize, void *PropValue);
-offload_impl_result_t
-offloadDeviceGetInfoSize_impl(offload_device_handle_t Device,
- offload_device_info_t PropName,
- size_t *PropSizeRet);
+ol_impl_result_t olGetDeviceInfoSize_impl(ol_device_handle_t Device,
+ ol_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 d94a62b967ae69..d2136143fd20ff 100644
--- a/offload/new-api/include/offload_print.hpp
+++ b/offload/new-api/include/offload_print.hpp
@@ -14,81 +14,79 @@
#include <ostream>
template <typename T>
-inline offload_result_t printPtr(std::ostream &os, const T *ptr);
+inline ol_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 <> struct is_handle<ol_platform_handle_t> : std::true_type {};
+template <> struct is_handle<ol_device_handle_t> : std::true_type {};
+template <> struct is_handle<ol_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_errc_t value);
+inline std::ostream &operator<<(std::ostream &os, enum ol_errc_t value);
inline std::ostream &operator<<(std::ostream &os,
- enum offload_platform_info_t value);
+ enum ol_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);
+ enum ol_platform_backend_t value);
+inline std::ostream &operator<<(std::ostream &os, enum ol_device_type_t value);
+inline std::ostream &operator<<(std::ostream &os, enum ol_device_info_t value);
///////////////////////////////////////////////////////////////////////////////
-/// @brief Print operator for the offload_errc_t type
+/// @brief Print operator for the ol_errc_t type
/// @returns std::ostream &
-inline std::ostream &operator<<(std::ostream &os, enum offload_errc_t value) {
+inline std::ostream &operator<<(std::ostream &os, enum ol_errc_t value) {
switch (value) {
- case OFFLOAD_ERRC_SUCCESS:
- os << "OFFLOAD_ERRC_SUCCESS";
+ case OL_ERRC_SUCCESS:
+ os << "OL_ERRC_SUCCESS";
break;
- case OFFLOAD_ERRC_INVALID_VALUE:
- os << "OFFLOAD_ERRC_INVALID_VALUE";
+ case OL_ERRC_INVALID_VALUE:
+ os << "OL_ERRC_INVALID_VALUE";
break;
- case OFFLOAD_ERRC_INVALID_PLATFORM:
- os << "OFFLOAD_ERRC_INVALID_PLATFORM";
+ case OL_ERRC_INVALID_PLATFORM:
+ os << "OL_ERRC_INVALID_PLATFORM";
break;
- case OFFLOAD_ERRC_DEVICE_NOT_FOUND:
- os << "OFFLOAD_ERRC_DEVICE_NOT_FOUND";
+ case OL_ERRC_DEVICE_NOT_FOUND:
+ os << "OL_ERRC_DEVICE_NOT_FOUND";
break;
- case OFFLOAD_ERRC_INVALID_DEVICE:
- os << "OFFLOAD_ERRC_INVALID_DEVICE";
+ case OL_ERRC_INVALID_DEVICE:
+ os << "OL_ERRC_INVALID_DEVICE";
break;
- case OFFLOAD_ERRC_DEVICE_LOST:
- os << "OFFLOAD_ERRC_DEVICE_LOST";
+ case OL_ERRC_DEVICE_LOST:
+ os << "OL_ERRC_DEVICE_LOST";
break;
- case OFFLOAD_ERRC_UNINITIALIZED:
- os << "OFFLOAD_ERRC_UNINITIALIZED";
+ case OL_ERRC_UNINITIALIZED:
+ os << "OL_ERRC_UNINITIALIZED";
break;
- case OFFLOAD_ERRC_OUT_OF_RESOURCES:
- os << "OFFLOAD_ERRC_OUT_OF_RESOURCES";
+ case OL_ERRC_OUT_OF_RESOURCES:
+ os << "OL_ERRC_OUT_OF_RESOURCES";
break;
- case OFFLOAD_ERRC_UNSUPPORTED_VERSION:
- os << "OFFLOAD_ERRC_UNSUPPORTED_VERSION";
+ case OL_ERRC_UNSUPPORTED_VERSION:
+ os << "OL_ERRC_UNSUPPORTED_VERSION";
break;
- case OFFLOAD_ERRC_UNSUPPORTED_FEATURE:
- os << "OFFLOAD_ERRC_UNSUPPORTED_FEATURE";
+ case OL_ERRC_UNSUPPORTED_FEATURE:
+ os << "OL_ERRC_UNSUPPORTED_FEATURE";
break;
- case OFFLOAD_ERRC_INVALID_ARGUMENT:
- os << "OFFLOAD_ERRC_INVALID_ARGUMENT";
+ case OL_ERRC_INVALID_ARGUMENT:
+ os << "OL_ERRC_INVALID_ARGUMENT";
break;
- case OFFLOAD_ERRC_INVALID_NULL_HANDLE:
- os << "OFFLOAD_ERRC_INVALID_NULL_HANDLE";
+ case OL_ERRC_INVALID_NULL_HANDLE:
+ os << "OL_ERRC_INVALID_NULL_HANDLE";
break;
- case OFFLOAD_ERRC_INVALID_NULL_POINTER:
- os << "OFFLOAD_ERRC_INVALID_NULL_POINTER";
+ case OL_ERRC_INVALID_NULL_POINTER:
+ os << "OL_ERRC_INVALID_NULL_POINTER";
break;
- case OFFLOAD_ERRC_INVALID_SIZE:
- os << "OFFLOAD_ERRC_INVALID_SIZE";
+ case OL_ERRC_INVALID_SIZE:
+ os << "OL_ERRC_INVALID_SIZE";
break;
- case OFFLOAD_ERRC_INVALID_ENUMERATION:
- os << "OFFLOAD_ERRC_INVALID_ENUMERATION";
+ case OL_ERRC_INVALID_ENUMERATION:
+ os << "OL_ERRC_INVALID_ENUMERATION";
break;
- case OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION:
- os << "OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION";
+ case OL_ERRC_UNSUPPORTED_ENUMERATION:
+ os << "OL_ERRC_UNSUPPORTED_ENUMERATION";
break;
- case OFFLOAD_ERRC_UNKNOWN:
- os << "OFFLOAD_ERRC_UNKNOWN";
+ case OL_ERRC_UNKNOWN:
+ os << "OL_ERRC_UNKNOWN";
break;
default:
os << "unknown enumerator";
@@ -98,22 +96,22 @@ inline std::ostream &operator<<(std::ostream &os, enum offload_errc_t value) {
}
///////////////////////////////////////////////////////////////////////////////
-/// @brief Print operator for the offload_platform_info_t type
+/// @brief Print operator for the ol_platform_info_t type
/// @returns std::ostream &
inline std::ostream &operator<<(std::ostream &os,
- enum offload_platform_info_t value) {
+ enum ol_platform_info_t value) {
switch (value) {
- case OFFLOAD_PLATFORM_INFO_NAME:
- os << "OFFLOAD_PLATFORM_INFO_NAME";
+ case OL_PLATFORM_INFO_NAME:
+ os << "OL_PLATFORM_INFO_NAME";
break;
- case OFFLOAD_PLATFORM_INFO_VENDOR_NAME:
- os << "OFFLOAD_PLATFORM_INFO_VENDOR_NAME";
+ case OL_PLATFORM_INFO_VENDOR_NAME:
+ os << "OL_PLATFORM_INFO_VENDOR_NAME";
break;
- case OFFLOAD_PLATFORM_INFO_VERSION:
- os << "OFFLOAD_PLATFORM_INFO_VERSION";
+ case OL_PLATFORM_INFO_VERSION:
+ os << "OL_PLATFORM_INFO_VERSION";
break;
- case OFFLOAD_PLATFORM_INFO_BACKEND:
- os << "OFFLOAD_PLATFORM_INFO_BACKEND";
+ case OL_PLATFORM_INFO_BACKEND:
+ os << "OL_PLATFORM_INFO_BACKEND";
break;
default:
os << "unknown enumerator";
@@ -123,32 +121,32 @@ inline std::ostream &operator<<(std::ostream &os,
}
///////////////////////////////////////////////////////////////////////////////
-/// @brief Print type-tagged offload_platform_info_t enum value
+/// @brief Print type-tagged ol_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) {
+ ol_platform_info_t value, size_t size) {
if (ptr == NULL) {
printPtr(os, ptr);
return;
}
switch (value) {
- case OFFLOAD_PLATFORM_INFO_NAME: {
+ case OL_PLATFORM_INFO_NAME: {
printPtr(os, (const char *)ptr);
break;
}
- case OFFLOAD_PLATFORM_INFO_VENDOR_NAME: {
+ case OL_PLATFORM_INFO_VENDOR_NAME: {
printPtr(os, (const char *)ptr);
break;
}
- case OFFLOAD_PLATFORM_INFO_VERSION: {
+ case OL_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;
+ case OL_PLATFORM_INFO_BACKEND: {
+ const ol_platform_backend_t *const tptr =
+ (const ol_platform_backend_t *const)ptr;
os << (const void *)tptr << " (";
os << *tptr;
os << ")";
@@ -160,19 +158,19 @@ inline void printTagged(std::ostream &os, const void *ptr,
}
}
///////////////////////////////////////////////////////////////////////////////
-/// @brief Print operator for the offload_platform_backend_t type
+/// @brief Print operator for the ol_platform_backend_t type
/// @returns std::ostream &
inline std::ostream &operator<<(std::ostream &os,
- enum offload_platform_backend_t value) {
+ enum ol_platform_backend_t value) {
switch (value) {
- case OFFLOAD_PLATFORM_BACKEND_UNKNOWN:
- os << "OFFLOAD_PLATFORM_BACKEND_UNKNOWN";
+ case OL_PLATFORM_BACKEND_UNKNOWN:
+ os << "OL_PLATFORM_BACKEND_UNKNOWN";
break;
- case OFFLOAD_PLATFORM_BACKEND_CUDA:
- os << "OFFLOAD_PLATFORM_BACKEND_CUDA";
+ case OL_PLATFORM_BACKEND_CUDA:
+ os << "OL_PLATFORM_BACKEND_CUDA";
break;
- case OFFLOAD_PLATFORM_BACKEND_AMDGPU:
- os << "OFFLOAD_PLATFORM_BACKEND_AMDGPU";
+ case OL_PLATFORM_BACKEND_AMDGPU:
+ os << "OL_PLATFORM_BACKEND_AMDGPU";
break;
default:
os << "unknown enumerator";
@@ -182,22 +180,21 @@ inline std::ostream &operator<<(std::ostream &os,
}
///////////////////////////////////////////////////////////////////////////////
-/// @brief Print operator for the offload_device_type_t type
+/// @brief Print operator for the ol_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 ol_device_type_t value) {
switch (value) {
- case OFFLOAD_DEVICE_TYPE_DEFAULT:
- os << "OFFLOAD_DEVICE_TYPE_DEFAULT";
+ case OL_DEVICE_TYPE_DEFAULT:
+ os << "OL_DEVICE_TYPE_DEFAULT";
break;
- case OFFLOAD_DEVICE_TYPE_ALL:
- os << "OFFLOAD_DEVICE_TYPE_ALL";
+ case OL_DEVICE_TYPE_ALL:
+ os << "OL_DEVICE_TYPE_ALL";
break;
- case OFFLOAD_DEVICE_TYPE_GPU:
- os << "OFFLOAD_DEVICE_TYPE_GPU";
+ case OL_DEVICE_TYPE_GPU:
+ os << "OL_DEVICE_TYPE_GPU";
break;
- case OFFLOAD_DEVICE_TYPE_CPU:
- os << "OFFLOAD_DEVICE_TYPE_CPU";
+ case OL_DEVICE_TYPE_CPU:
+ os << "OL_DEVICE_TYPE_CPU";
break;
default:
os << "unknown enumerator";
@@ -207,25 +204,24 @@ inline std::ostream &operator<<(std::ostream &os,
}
///////////////////////////////////////////////////////////////////////////////
-/// @brief Print operator for the offload_device_info_t type
+/// @brief Print operator for the ol_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 ol_device_info_t value) {
switch (value) {
- case OFFLOAD_DEVICE_INFO_TYPE:
- os << "OFFLOAD_DEVICE_INFO_TYPE";
+ case OL_DEVICE_INFO_TYPE:
+ os << "OL_DEVICE_INFO_TYPE";
break;
- case OFFLOAD_DEVICE_INFO_PLATFORM:
- os << "OFFLOAD_DEVICE_INFO_PLATFORM";
+ case OL_DEVICE_INFO_PLATFORM:
+ os << "OL_DEVICE_INFO_PLATFORM";
break;
- case OFFLOAD_DEVICE_INFO_NAME:
- os << "OFFLOAD_DEVICE_INFO_NAME";
+ case OL_DEVICE_INFO_NAME:
+ os << "OL_DEVICE_INFO_NAME";
break;
- case OFFLOAD_DEVICE_INFO_VENDOR:
- os << "OFFLOAD_DEVICE_INFO_VENDOR";
+ case OL_DEVICE_INFO_VENDOR:
+ os << "OL_DEVICE_INFO_VENDOR";
break;
- case OFFLOAD_DEVICE_INFO_DRIVER_VERSION:
- os << "OFFLOAD_DEVICE_INFO_DRIVER_VERSION";
+ case OL_DEVICE_INFO_DRIVER_VERSION:
+ os << "OL_DEVICE_INFO_DRIVER_VERSION";
break;
default:
os << "unknown enumerator";
@@ -235,42 +231,41 @@ inline std::ostream &operator<<(std::ostream &os,
}
///////////////////////////////////////////////////////////////////////////////
-/// @brief Print type-tagged offload_device_info_t enum value
+/// @brief Print type-tagged ol_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) {
+ ol_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;
+ case OL_DEVICE_INFO_TYPE: {
+ const ol_device_type_t *const tptr = (const ol_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;
+ case OL_DEVICE_INFO_PLATFORM: {
+ const ol_platform_handle_t *const tptr =
+ (const ol_platform_handle_t *const)ptr;
os << (const void *)tptr << " (";
os << *tptr;
os << ")";
break;
}
- case OFFLOAD_DEVICE_INFO_NAME: {
+ case OL_DEVICE_INFO_NAME: {
printPtr(os, (const char *)ptr);
break;
}
- case OFFLOAD_DEVICE_INFO_VENDOR: {
+ case OL_DEVICE_INFO_VENDOR: {
printPtr(os, (const char *)ptr);
break;
}
- case OFFLOAD_DEVICE_INFO_DRIVER_VERSION: {
+ case OL_DEVICE_INFO_DRIVER_VERSION: {
printPtr(os, (const char *)ptr);
break;
}
@@ -281,18 +276,17 @@ inline void printTagged(std::ostream &os, const void *ptr,
}
inline std::ostream &operator<<(std::ostream &os,
- const offload_error_struct_t *Err) {
+ const ol_error_struct_t *Err) {
if (Err == nullptr) {
- os << "OFFLOAD_RESULT_SUCCESS";
+ os << "OL_SUCCESS";
} else {
os << Err->Code;
}
return os;
}
-inline std::ostream &
-operator<<(std::ostream &os,
- const struct offload_platform_get_params_t *params) {
+inline std::ostream &operator<<(std::ostream &os,
+ const struct ol_get_platform_params_t *params) {
os << ".NumEntries = ";
os << *params->pNumEntries;
os << ", ";
@@ -310,7 +304,7 @@ operator<<(std::ostream &os,
inline std::ostream &
operator<<(std::ostream &os,
- const struct offload_platform_get_count_params_t *params) {
+ const struct ol_get_platform_count_params_t *params) {
os << ".NumPlatforms = ";
printPtr(os, *params->pNumPlatforms);
return os;
@@ -318,7 +312,7 @@ operator<<(std::ostream &os,
inline std::ostream &
operator<<(std::ostream &os,
- const struct offload_platform_get_info_params_t *params) {
+ const struct ol_get_platform_info_params_t *params) {
os << ".Platform = ";
printPtr(os, *params->pPlatform);
os << ", ";
@@ -335,7 +329,7 @@ operator<<(std::ostream &os,
inline std::ostream &
operator<<(std::ostream &os,
- const struct offload_platform_get_info_size_params_t *params) {
+ const struct ol_get_platform_info_size_params_t *params) {
os << ".Platform = ";
printPtr(os, *params->pPlatform);
os << ", ";
@@ -349,7 +343,7 @@ operator<<(std::ostream &os,
inline std::ostream &
operator<<(std::ostream &os,
- const struct offload_device_get_count_params_t *params) {
+ const struct ol_get_device_count_params_t *params) {
os << ".Platform = ";
printPtr(os, *params->pPlatform);
os << ", ";
@@ -358,8 +352,8 @@ operator<<(std::ostream &os,
return os;
}
-inline std::ostream &
-operator<<(std::ostream &os, const struct offload_device_get_params_t *params) {
+inline std::ostream &operator<<(std::ostream &os,
+ const struct ol_get_device_params_t *params) {
os << ".Platform = ";
printPtr(os, *params->pPlatform);
os << ", ";
@@ -379,8 +373,7 @@ operator<<(std::ostream &os, const struct offload_device_get_params_t *params) {
}
inline std::ostream &
-operator<<(std::ostream &os,
- const struct offload_device_get_info_params_t *params) {
+operator<<(std::ostream &os, const struct ol_get_device_info_params_t *params) {
os << ".Device = ";
printPtr(os, *params->pDevice);
os << ", ";
@@ -397,7 +390,7 @@ operator<<(std::ostream &os,
inline std::ostream &
operator<<(std::ostream &os,
- const struct offload_device_get_info_size_params_t *params) {
+ const struct ol_get_device_info_size_params_t *params) {
os << ".Device = ";
printPtr(os, *params->pDevice);
os << ", ";
@@ -412,7 +405,7 @@ operator<<(std::ostream &os,
///////////////////////////////////////////////////////////////////////////////
// @brief Print pointer value
template <typename T>
-inline offload_result_t printPtr(std::ostream &os, const T *ptr) {
+inline ol_result_t printPtr(std::ostream &os, const T *ptr) {
if (ptr == nullptr) {
os << "nullptr";
} else if constexpr (std::is_pointer_v<T>) {
@@ -431,5 +424,5 @@ inline offload_result_t printPtr(std::ostream &os, const T *ptr) {
os << ")";
}
- return OFFLOAD_RESULT_SUCCESS;
+ return OL_SUCCESS;
}
diff --git a/offload/new-api/src/helpers.hpp b/offload/new-api/src/helpers.hpp
index e24bd58bc11111..8aa8e319b278bd 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_errc_t getInfoImpl(size_t ParamValueSize, void *ParamValue,
- size_t *ParamValueSizeRet, T Value, size_t ValueSize,
- Assign &&AssignFunc) {
+ol_errc_t getInfoImpl(size_t ParamValueSize, void *ParamValue,
+ size_t *ParamValueSizeRet, T Value, size_t ValueSize,
+ Assign &&AssignFunc) {
if (!ParamValue && !ParamValueSizeRet) {
- return OFFLOAD_ERRC_INVALID_NULL_POINTER;
+ return OL_ERRC_INVALID_NULL_POINTER;
}
if (ParamValue != nullptr) {
if (ParamValueSize < ValueSize) {
- return OFFLOAD_ERRC_INVALID_SIZE;
+ return OL_ERRC_INVALID_SIZE;
}
AssignFunc(ParamValue, Value, ValueSize);
}
@@ -35,12 +35,12 @@ offload_errc_t getInfoImpl(size_t ParamValueSize, void *ParamValue,
*ParamValueSizeRet = ValueSize;
}
- return OFFLOAD_ERRC_SUCCESS;
+ return OL_ERRC_SUCCESS;
}
template <typename T>
-offload_errc_t getInfo(size_t ParamValueSize, void *ParamValue,
- size_t *ParamValueSizeRet, T Value) {
+ol_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,17 +50,17 @@ offload_errc_t getInfo(size_t ParamValueSize, void *ParamValue,
}
template <typename T>
-offload_errc_t getInfoArray(size_t array_length, size_t ParamValueSize,
- void *ParamValue, size_t *ParamValueSizeRet,
- const T *Value) {
+ol_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_errc_t
-getInfo<const char *>(size_t ParamValueSize, void *ParamValue,
- size_t *ParamValueSizeRet, const char *Value) {
+inline ol_errc_t getInfo<const char *>(size_t ParamValueSize, void *ParamValue,
+ size_t *ParamValueSizeRet,
+ const char *Value) {
return getInfoArray(strlen(Value) + 1, ParamValueSize, ParamValue,
ParamValueSizeRet, Value);
}
@@ -79,12 +79,12 @@ class ReturnHelper {
ParamValueSizeRet(ParamValueSize) {}
// Scalar return Value
- template <class T> offload_errc_t operator()(const T &t) {
+ template <class T> ol_errc_t operator()(const T &t) {
return getInfo(ParamValueSize, ParamValue, ParamValueSizeRet, t);
}
// Array return Value
- template <class T> offload_errc_t operator()(const T *t, size_t s) {
+ template <class T> ol_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 d62e4831e17756..c9f20440dc266c 100644
--- a/offload/new-api/src/offload_impl.cpp
+++ b/offload/new-api/src/offload_impl.cpp
@@ -1,4 +1,4 @@
-//===- offload_impl.cpp - Implementation of the new LLVM/Offload API ------===//
+//===- ol_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.
@@ -23,19 +23,19 @@ 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_ {
+struct ol_device_handle_t_ {
int DeviceNum;
GenericDeviceTy &Device;
- offload_platform_handle_t Platform;
+ ol_platform_handle_t Platform;
};
-struct offload_platform_handle_t_ {
+struct ol_platform_handle_t_ {
std::unique_ptr<GenericPluginTy> Plugin;
- std::vector<offload_device_handle_t_> Devices;
+ std::vector<ol_device_handle_t_> Devices;
};
-std::vector<offload_platform_handle_t_> &Platforms() {
- static std::vector<offload_platform_handle_t_> Platforms;
+std::vector<ol_platform_handle_t_> &Platforms() {
+ static std::vector<ol_platform_handle_t_> Platforms;
return Platforms;
}
@@ -47,7 +47,7 @@ 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(ol_platform_handle_t_{ \
std::unique_ptr<GenericPluginTy>(createPlugin_##Name()), {}}); \
} while (false);
#include "Shared/Targets.def"
@@ -60,7 +60,7 @@ void initPlugins() {
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_{
+ Platform.Devices.emplace_back(ol_device_handle_t_{
DevNum, Platform.Plugin->getDevice(DevNum), &Platform});
}
}
@@ -71,24 +71,23 @@ void initPlugins() {
// TODO: We can properly reference count here and manage the resources in a more
// clever way
-offload_impl_result_t offloadInit_impl() {
+ol_impl_result_t olInit_impl() {
static std::once_flag InitFlag;
std::call_once(InitFlag, initPlugins);
- return OFFLOAD_RESULT_SUCCESS;
+ return OL_SUCCESS;
}
-offload_impl_result_t offloadShutDown_impl() { return OFFLOAD_RESULT_SUCCESS; }
+ol_impl_result_t olShutDown_impl() { return OL_SUCCESS; }
-offload_impl_result_t offloadPlatformGetCount_impl(uint32_t *NumPlatforms) {
+ol_impl_result_t olGetPlatformCount_impl(uint32_t *NumPlatforms) {
*NumPlatforms = Platforms().size();
- return OFFLOAD_RESULT_SUCCESS;
+ return OL_SUCCESS;
}
-offload_impl_result_t
-offloadPlatformGet_impl(uint32_t NumEntries,
- offload_platform_handle_t *PlatformsOut) {
+ol_impl_result_t olGetPlatform_impl(uint32_t NumEntries,
+ ol_platform_handle_t *PlatformsOut) {
if (NumEntries > Platforms().size()) {
- return {OFFLOAD_ERRC_INVALID_SIZE,
+ return {OL_ERRC_INVALID_SIZE,
std::string{formatv("{0} platform(s) available but {1} requested.",
Platforms().size(), NumEntries)}};
}
@@ -98,91 +97,89 @@ offloadPlatformGet_impl(uint32_t NumEntries,
PlatformsOut[PlatformIndex] = &(Platforms())[PlatformIndex];
}
- return OFFLOAD_RESULT_SUCCESS;
+ return OL_SUCCESS;
}
-offload_impl_result_t offloadPlatformGetInfoImplDetail(
- offload_platform_handle_t Platform, offload_platform_info_t PropName,
- size_t PropSize, void *PropValue, size_t *PropSizeRet) {
+ol_impl_result_t olGetPlatformInfoImplDetail(ol_platform_handle_t Platform,
+ ol_platform_info_t PropName,
+ size_t PropSize, void *PropValue,
+ size_t *PropSizeRet) {
ReturnHelper ReturnValue(PropSize, PropValue, PropSizeRet);
switch (PropName) {
- case OFFLOAD_PLATFORM_INFO_NAME:
+ case OL_PLATFORM_INFO_NAME:
return ReturnValue(Platform->Plugin->getName());
- case OFFLOAD_PLATFORM_INFO_VENDOR_NAME:
+ case OL_PLATFORM_INFO_VENDOR_NAME:
// TODO: Implement this
return ReturnValue("Unknown platform vendor");
- case OFFLOAD_PLATFORM_INFO_VERSION: {
- return ReturnValue(formatv("v{0}.{1}.{2}", OFFLOAD_VERSION_MAJOR,
- OFFLOAD_VERSION_MINOR, OFFLOAD_VERSION_PATCH)
+ case OL_PLATFORM_INFO_VERSION: {
+ return ReturnValue(formatv("v{0}.{1}.{2}", OL_VERSION_MAJOR,
+ OL_VERSION_MINOR, OL_VERSION_PATCH)
.str()
.c_str());
}
- case OFFLOAD_PLATFORM_INFO_BACKEND: {
+ case OL_PLATFORM_INFO_BACKEND: {
auto PluginName = Platform->Plugin->getName();
if (PluginName == StringRef("CUDA")) {
- return ReturnValue(OFFLOAD_PLATFORM_BACKEND_CUDA);
+ return ReturnValue(OL_PLATFORM_BACKEND_CUDA);
} else if (PluginName == StringRef("AMDGPU")) {
- return ReturnValue(OFFLOAD_PLATFORM_BACKEND_AMDGPU);
+ return ReturnValue(OL_PLATFORM_BACKEND_AMDGPU);
} else {
- return ReturnValue(OFFLOAD_PLATFORM_BACKEND_UNKNOWN);
+ return ReturnValue(OL_PLATFORM_BACKEND_UNKNOWN);
}
}
default:
- return OFFLOAD_ERRC_INVALID_ENUMERATION;
+ return OL_ERRC_INVALID_ENUMERATION;
}
- return OFFLOAD_RESULT_SUCCESS;
+ return OL_SUCCESS;
}
-offload_impl_result_t
-offloadPlatformGetInfo_impl(offload_platform_handle_t Platform,
- offload_platform_info_t PropName, size_t PropSize,
- void *PropValue) {
- return offloadPlatformGetInfoImplDetail(Platform, PropName, PropSize,
- PropValue, nullptr);
+ol_impl_result_t olGetPlatformInfo_impl(ol_platform_handle_t Platform,
+ ol_platform_info_t PropName,
+ size_t PropSize, void *PropValue) {
+ return olGetPlatformInfoImplDetail(Platform, PropName, PropSize, PropValue,
+ nullptr);
}
-offload_impl_result_t
-offloadPlatformGetInfoSize_impl(offload_platform_handle_t Platform,
- offload_platform_info_t PropName,
- size_t *PropSizeRet) {
- return offloadPlatformGetInfoImplDetail(Platform, PropName, 0, nullptr,
- PropSizeRet);
+ol_impl_result_t olGetPlatformInfoSize_impl(ol_platform_handle_t Platform,
+ ol_platform_info_t PropName,
+ size_t *PropSizeRet) {
+ return olGetPlatformInfoImplDetail(Platform, PropName, 0, nullptr,
+ PropSizeRet);
}
-offload_impl_result_t
-offloadDeviceGetCount_impl(offload_platform_handle_t Platform,
- uint32_t *pNumDevices) {
+ol_impl_result_t olGetDeviceCount_impl(ol_platform_handle_t Platform,
+ uint32_t *pNumDevices) {
*pNumDevices = static_cast<uint32_t>(Platform->Devices.size());
- return OFFLOAD_RESULT_SUCCESS;
+ return OL_SUCCESS;
}
-offload_impl_result_t offloadDeviceGet_impl(offload_platform_handle_t Platform,
- uint32_t NumEntries,
- offload_device_handle_t *Devices) {
+ol_impl_result_t olGetDevice_impl(ol_platform_handle_t Platform,
+ uint32_t NumEntries,
+ ol_device_handle_t *Devices) {
if (NumEntries > Platform->Devices.size()) {
- return OFFLOAD_ERRC_INVALID_SIZE;
+ return OL_ERRC_INVALID_SIZE;
}
for (uint32_t DeviceIndex = 0; DeviceIndex < NumEntries; DeviceIndex++) {
Devices[DeviceIndex] = &(Platform->Devices[DeviceIndex]);
}
- return OFFLOAD_RESULT_SUCCESS;
+ return OL_SUCCESS;
}
-offload_impl_result_t
-offloadDeviceGetInfoImplDetail(offload_device_handle_t Device,
- offload_device_info_t PropName, size_t PropSize,
- void *PropValue, size_t *PropSizeRet) {
+ol_impl_result_t olGetDeviceInfoImplDetail(ol_device_handle_t Device,
+ ol_device_info_t PropName,
+ size_t PropSize, void *PropValue,
+ size_t *PropSizeRet) {
ReturnHelper ReturnValue(PropSize, PropValue, PropSizeRet);
InfoQueueTy DevInfo;
if (auto Err = Device->Device.obtainInfoImpl(DevInfo))
- return OFFLOAD_ERRC_OUT_OF_RESOURCES;
+ return OL_ERRC_OUT_OF_RESOURCES;
// Find the info if it exists under any of the given names
auto GetInfo = [&DevInfo](std::vector<std::string> Names) {
@@ -202,36 +199,33 @@ offloadDeviceGetInfoImplDetail(offload_device_handle_t Device,
};
switch (PropName) {
- case OFFLOAD_DEVICE_INFO_PLATFORM:
+ case OL_DEVICE_INFO_PLATFORM:
return ReturnValue(Device->Platform);
- case OFFLOAD_DEVICE_INFO_TYPE:
- return ReturnValue(OFFLOAD_DEVICE_TYPE_GPU);
- case OFFLOAD_DEVICE_INFO_NAME:
+ case OL_DEVICE_INFO_TYPE:
+ return ReturnValue(OL_DEVICE_TYPE_GPU);
+ case OL_DEVICE_INFO_NAME:
return ReturnValue(GetInfo({"Device Name"}).c_str());
- case OFFLOAD_DEVICE_INFO_VENDOR:
+ case OL_DEVICE_INFO_VENDOR:
return ReturnValue(GetInfo({"Vendor Name"}).c_str());
- case OFFLOAD_DEVICE_INFO_DRIVER_VERSION:
+ case OL_DEVICE_INFO_DRIVER_VERSION:
return ReturnValue(
GetInfo({"CUDA Driver Version", "HSA Runtime Version"}).c_str());
default:
- return OFFLOAD_ERRC_INVALID_ENUMERATION;
+ return OL_ERRC_INVALID_ENUMERATION;
}
- return OFFLOAD_RESULT_SUCCESS;
+ return OL_SUCCESS;
}
-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);
+ol_impl_result_t olGetDeviceInfo_impl(ol_device_handle_t Device,
+ ol_device_info_t PropName,
+ size_t PropSize, void *PropValue) {
+ return olGetDeviceInfoImplDetail(Device, PropName, PropSize, PropValue,
+ nullptr);
}
-offload_impl_result_t
-offloadDeviceGetInfoSize_impl(offload_device_handle_t Device,
- offload_device_info_t PropName,
- size_t *PropSizeRet) {
- return offloadDeviceGetInfoImplDetail(Device, PropName, 0, nullptr,
- PropSizeRet);
+ol_impl_result_t olGetDeviceInfoSize_impl(ol_device_handle_t Device,
+ ol_device_info_t PropName,
+ size_t *PropSizeRet) {
+ return olGetDeviceInfoImplDetail(Device, PropName, 0, nullptr, PropSizeRet);
}
diff --git a/offload/new-api/src/offload_lib.cpp b/offload/new-api/src/offload_lib.cpp
index 20beb72575c3eb..29cb614844875a 100644
--- a/offload/new-api/src/offload_lib.cpp
+++ b/offload/new-api/src/offload_lib.cpp
@@ -26,8 +26,8 @@ ErrSetT &errors() {
return Errors;
}
-offload_code_location_t *¤tCodeLocation() {
- thread_local offload_code_location_t *CodeLoc = nullptr;
+ol_code_location_t *¤tCodeLocation() {
+ thread_local ol_code_location_t *CodeLoc = nullptr;
return CodeLoc;
}
diff --git a/offload/test/tools/offload-tblgen/type_tagged_enum.td b/offload/test/tools/offload-tblgen/type_tagged_enum.td
index ff9c91f88c5382..ea83545e0a3859 100644
--- a/offload/test/tools/offload-tblgen/type_tagged_enum.td
+++ b/offload/test/tools/offload-tblgen/type_tagged_enum.td
@@ -4,7 +4,7 @@
// Check that type-tagged enumerators are implemented correctly. They enable
// functions to return data of an arbitrary type and size via a void*, using
// the value of an enum parameter to indicate which type is being returned.
-// This allows, for example, for a single offloadDeviceGetInfo function, rather
+// This allows, for example, for a single olGetDeviceInfo function, rather
// than requiring a separate entry point for every possible query.
include "APIDefs.td"
diff --git a/offload/tools/offload-tblgen/APIGen.cpp b/offload/tools/offload-tblgen/APIGen.cpp
index 2d5f6d538199fa..877b57f24a2b8a 100644
--- a/offload/tools/offload-tblgen/APIGen.cpp
+++ b/offload/tools/offload-tblgen/APIGen.cpp
@@ -185,7 +185,7 @@ static void ProcessFuncWithCodeLocVariant(const FunctionRec &Func,
///////////////////////////////////////////////////////////////////////////////
/// @brief Variant of {0} that also sets source code location information
/// @details See also ::{0}
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL {0}WithCodeLoc(
+OL_APIEXPORT ol_result_t OL_APICALL {0}WithCodeLoc(
)";
OS << formatv(FuncWithCodeLocBegin, Func.getName());
auto Params = Func.getParams();
@@ -193,7 +193,7 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL {0}WithCodeLoc(
OS << " " << Param.getType() << " " << Param.getName();
OS << ",\n";
}
- OS << "offload_code_location_t *CodeLocation);\n\n";
+ OS << "ol_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 82d4f85126dffa..6e85ebd9bfd673 100644
--- a/offload/tools/offload-tblgen/EntryPointGen.cpp
+++ b/offload/tools/offload-tblgen/EntryPointGen.cpp
@@ -118,7 +118,7 @@ static void EmitCodeLocWrapper(const FunctionRec &F, raw_ostream &OS) {
ParamNameList += ", ";
}
}
- OS << "offload_code_location_t *CodeLocation";
+ OS << "ol_code_location_t *CodeLocation";
OS << ") {\n";
OS << TAB_1 "currentCodeLocation() = CodeLocation;\n";
OS << formatv(TAB_1 "{0}_result_t Result = {1}({2});\n\n", PrefixLower,
diff --git a/offload/tools/offload-tblgen/GenCommon.hpp b/offload/tools/offload-tblgen/GenCommon.hpp
index 64df6be8442207..db432e9958b5d5 100644
--- a/offload/tools/offload-tblgen/GenCommon.hpp
+++ b/offload/tools/offload-tblgen/GenCommon.hpp
@@ -56,8 +56,8 @@ constexpr auto CommentsHeader = R"(
constexpr auto CommentsBreak = "///\n";
-constexpr auto PrefixLower = "offload";
-constexpr auto PrefixUpper = "OFFLOAD";
+constexpr auto PrefixLower = "ol";
+constexpr auto PrefixUpper = "OL";
inline std::string
MakeParamComment(const llvm::offload::tblgen::ParamRec &Param) {
diff --git a/offload/tools/offload-tblgen/PrintGen.cpp b/offload/tools/offload-tblgen/PrintGen.cpp
index f5edbed88f184e..9a288139dc7a2d 100644
--- a/offload/tools/offload-tblgen/PrintGen.cpp
+++ b/offload/tools/offload-tblgen/PrintGen.cpp
@@ -97,9 +97,9 @@ 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) {
+ const ol_error_struct_t *Err) {
if (Err == nullptr) {
- os << "OFFLOAD_RESULT_SUCCESS";
+ os << "OL_SUCCESS";
} else {
os << Err->Code;
}
@@ -161,7 +161,7 @@ void EmitOffloadPrintHeader(RecordKeeper &Records, raw_ostream &OS) {
#include <ostream>
-template <typename T> inline offload_result_t printPtr(std::ostream &os, const T *ptr);
+template <typename T> inline ol_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);
)""";
@@ -201,7 +201,7 @@ template <typename T> inline void printTagged(std::ostream &os, const void *ptr,
OS << R"""(
///////////////////////////////////////////////////////////////////////////////
// @brief Print pointer value
-template <typename T> inline offload_result_t printPtr(std::ostream &os, const T *ptr) {
+template <typename T> inline ol_result_t printPtr(std::ostream &os, const T *ptr) {
if (ptr == nullptr) {
os << "nullptr";
} else if constexpr (std::is_pointer_v<T>) {
@@ -220,7 +220,7 @@ template <typename T> inline offload_result_t printPtr(std::ostream &os, const T
os << ")";
}
- return OFFLOAD_RESULT_SUCCESS;
+ return OL_SUCCESS;
}
)""";
}
diff --git a/offload/unittests/OffloadAPI/CMakeLists.txt b/offload/unittests/OffloadAPI/CMakeLists.txt
index 276eb2be281922..c5d4473d39dc45 100644
--- a/offload/unittests/OffloadAPI/CMakeLists.txt
+++ b/offload/unittests/OffloadAPI/CMakeLists.txt
@@ -3,14 +3,14 @@ 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/offloadDeviceGetCount.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/device/offloadDeviceGetInfo.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/device/offloadDeviceGetInfoSize.cpp)
+ ${CMAKE_CURRENT_SOURCE_DIR}/platform/olGetPlatform.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/platform/olGetPlatformCount.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/platform/olGetPlatformInfo.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/platform/olGetPlatformInfoSize.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/device/olGetDevice.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/device/olGetDeviceCount.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/device/olGetDeviceInfo.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/device/olGetDeviceInfoSize.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 ec71495d278552..f1763c706d0851 100644
--- a/offload/unittests/OffloadAPI/common/environment.cpp
+++ b/offload/unittests/OffloadAPI/common/environment.cpp
@@ -16,8 +16,8 @@ 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(); }
+ OffloadInitWrapper() { olInit(); }
+ ~OffloadInitWrapper() { olShutDown(); }
};
static OffloadInitWrapper Wrapper{};
@@ -26,34 +26,32 @@ static cl::opt<std::string>
cl::value_desc("platform"));
std::ostream &operator<<(std::ostream &Out,
- const offload_platform_handle_t &Platform) {
+ const ol_platform_handle_t &Platform) {
size_t Size;
- offloadPlatformGetInfoSize(Platform, OFFLOAD_PLATFORM_INFO_NAME, &Size);
+ olGetPlatformInfoSize(Platform, OL_PLATFORM_INFO_NAME, &Size);
std::vector<char> Name(Size);
- offloadPlatformGetInfo(Platform, OFFLOAD_PLATFORM_INFO_NAME, Size,
- Name.data());
+ olGetPlatformInfo(Platform, OL_PLATFORM_INFO_NAME, Size, Name.data());
Out << Name.data();
return Out;
}
-std::ostream &
-operator<<(std::ostream &Out,
- const std::vector<offload_platform_handle_t> &Platforms) {
+std::ostream &operator<<(std::ostream &Out,
+ const std::vector<ol_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{};
+const std::vector<ol_platform_handle_t> &TestEnvironment::getPlatforms() {
+ static std::vector<ol_platform_handle_t> Platforms{};
if (Platforms.empty()) {
uint32_t PlatformCount = 0;
- offloadPlatformGetCount(&PlatformCount);
+ olGetPlatformCount(&PlatformCount);
if (PlatformCount > 0) {
Platforms.resize(PlatformCount);
- offloadPlatformGet(PlatformCount, Platforms.data());
+ olGetPlatform(PlatformCount, Platforms.data());
}
}
@@ -61,8 +59,8 @@ const std::vector<offload_platform_handle_t> &TestEnvironment::getPlatforms() {
}
// Get a single platform, which may be selected by the user.
-offload_platform_handle_t TestEnvironment::getPlatform() {
- static offload_platform_handle_t Platform = nullptr;
+ol_platform_handle_t TestEnvironment::getPlatform() {
+ static ol_platform_handle_t Platform = nullptr;
const auto &Platforms = getPlatforms();
if (!Platform) {
@@ -84,8 +82,7 @@ offload_platform_handle_t TestEnvironment::getPlatform() {
Platform = Platforms[0];
for (auto CandidatePlatform : Platforms) {
uint32_t NumDevices = 0;
- if (offloadDeviceGetCount(CandidatePlatform, &NumDevices) ==
- OFFLOAD_RESULT_SUCCESS) {
+ if (olGetDeviceCount(CandidatePlatform, &NumDevices) == OL_SUCCESS) {
if (NumDevices > 0) {
Platform = CandidatePlatform;
break;
diff --git a/offload/unittests/OffloadAPI/common/environment.hpp b/offload/unittests/OffloadAPI/common/environment.hpp
index 3e85c54c7413eb..6fb9291ff88149 100644
--- a/offload/unittests/OffloadAPI/common/environment.hpp
+++ b/offload/unittests/OffloadAPI/common/environment.hpp
@@ -12,6 +12,6 @@
#include <offload_api.h>
namespace TestEnvironment {
-const std::vector<offload_platform_handle_t> &getPlatforms();
-offload_platform_handle_t getPlatform();
+const std::vector<ol_platform_handle_t> &getPlatforms();
+ol_platform_handle_t getPlatform();
} // namespace TestEnvironment
diff --git a/offload/unittests/OffloadAPI/common/fixtures.hpp b/offload/unittests/OffloadAPI/common/fixtures.hpp
index 7c5e85acb8d94e..5d93c4cb2e5ac7 100644
--- a/offload/unittests/OffloadAPI/common/fixtures.hpp
+++ b/offload/unittests/OffloadAPI/common/fixtures.hpp
@@ -15,14 +15,14 @@
#pragma once
#ifndef ASSERT_SUCCESS
-#define ASSERT_SUCCESS(ACTUAL) ASSERT_EQ(OFFLOAD_RESULT_SUCCESS, ACTUAL)
+#define ASSERT_SUCCESS(ACTUAL) ASSERT_EQ(OL_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; \
+ ol_result_t Res = ACTUAL; \
ASSERT_TRUE(Res && (Res->Code == EXPECTED)); \
} while (0)
#endif
@@ -46,7 +46,7 @@ struct offloadPlatformTest : offloadTest {
ASSERT_NE(Platform, nullptr);
}
- offload_platform_handle_t Platform;
+ ol_platform_handle_t Platform;
};
struct offloadDeviceTest : offloadPlatformTest {
@@ -54,12 +54,12 @@ struct offloadDeviceTest : offloadPlatformTest {
RETURN_ON_FATAL_FAILURE(offloadPlatformTest::SetUp());
uint32_t NumDevices;
- ASSERT_SUCCESS(offloadDeviceGetCount(Platform, &NumDevices));
+ ASSERT_SUCCESS(olGetDeviceCount(Platform, &NumDevices));
if (NumDevices == 0) {
GTEST_SKIP() << "No available devices on this platform.";
}
- ASSERT_SUCCESS(offloadDeviceGet(Platform, 1, &Device));
+ ASSERT_SUCCESS(olGetDevice(Platform, 1, &Device));
}
- offload_device_handle_t Device;
+ ol_device_handle_t Device;
};
diff --git a/offload/unittests/OffloadAPI/device/offloadDeviceGetCount.cpp b/offload/unittests/OffloadAPI/device/offloadDeviceGetCount.cpp
deleted file mode 100644
index 87ebbef1d8b7d8..00000000000000
--- a/offload/unittests/OffloadAPI/device/offloadDeviceGetCount.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-//===------- 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
deleted file mode 100644
index 099bc3abcf8c4b..00000000000000
--- a/offload/unittests/OffloadAPI/device/offloadDeviceGetInfo.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-//===------- 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 "offloadDeviceInfo.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()); }
-};
-
-INSTANTIATE_TEST_SUITE_P(
- , offloadDeviceGetInfoTest, ::testing::ValuesIn(DeviceQueries),
- [](const ::testing::TestParamInfo<offload_device_info_t> &info) {
- std::stringstream ss;
- ss << info.param;
- return ss.str();
- });
-
-TEST_P(offloadDeviceGetInfoTest, Success) {
- offload_device_info_t InfoType = GetParam();
- size_t Size = 0;
-
- ASSERT_SUCCESS(offloadDeviceGetInfoSize(Device, InfoType, &Size));
-
- std::vector<char> InfoData(Size);
- ASSERT_SUCCESS(offloadDeviceGetInfo(Device, InfoType, Size, InfoData.data()));
-
- 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_ERROR(OFFLOAD_ERRC_INVALID_NULL_HANDLE,
- offloadDeviceGetInfo(nullptr, OFFLOAD_DEVICE_INFO_TYPE,
- 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));
-}
-
-TEST_F(offloadDeviceGetInfoTest, InvalidSizePropSize) {
- offload_device_type_t DeviceType;
- 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));
-}
-
-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));
-}
diff --git a/offload/unittests/OffloadAPI/device/offloadDeviceGetInfoSize.cpp b/offload/unittests/OffloadAPI/device/offloadDeviceGetInfoSize.cpp
deleted file mode 100644
index 8e08a59af902c2..00000000000000
--- a/offload/unittests/OffloadAPI/device/offloadDeviceGetInfoSize.cpp
+++ /dev/null
@@ -1,61 +0,0 @@
-//===------- 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/olDeviceInfo.hpp
similarity index 52%
rename from offload/unittests/OffloadAPI/device/offloadDeviceInfo.hpp
rename to offload/unittests/OffloadAPI/device/olDeviceInfo.hpp
index 064935ac10107f..06915258da3842 100644
--- a/offload/unittests/OffloadAPI/device/offloadDeviceInfo.hpp
+++ b/offload/unittests/OffloadAPI/device/olDeviceInfo.hpp
@@ -11,12 +11,11 @@
#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::vector<ol_device_info_t> DeviceQueries = {
+ OL_DEVICE_INFO_TYPE, OL_DEVICE_INFO_PLATFORM, OL_DEVICE_INFO_NAME,
+ OL_DEVICE_INFO_VENDOR, OL_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)},
+inline std::unordered_map<ol_device_info_t, size_t> DeviceInfoSizeMap = {
+ {OL_DEVICE_INFO_TYPE, sizeof(ol_device_type_t)},
+ {OL_DEVICE_INFO_PLATFORM, sizeof(ol_platform_handle_t)},
};
diff --git a/offload/unittests/OffloadAPI/device/offloadDeviceGet.cpp b/offload/unittests/OffloadAPI/device/olGetDevice.cpp
similarity index 52%
rename from offload/unittests/OffloadAPI/device/offloadDeviceGet.cpp
rename to offload/unittests/OffloadAPI/device/olGetDevice.cpp
index c14fd3997ee62d..5d115b7326d202 100644
--- a/offload/unittests/OffloadAPI/device/offloadDeviceGet.cpp
+++ b/offload/unittests/OffloadAPI/device/olGetDevice.cpp
@@ -1,4 +1,4 @@
-//===------- Offload API tests - offloadDeviceGet -------------------------===//
+//===------- Offload API tests - olGetDevice -------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -10,27 +10,27 @@
#include <gtest/gtest.h>
#include <offload_api.h>
-using offloadDeviceGetTest = offloadPlatformTest;
+using olGetDeviceTest = offloadPlatformTest;
-TEST_F(offloadDeviceGetTest, Success) {
+TEST_F(olGetDeviceTest, Success) {
uint32_t Count = 0;
- ASSERT_SUCCESS(offloadDeviceGetCount(Platform, &Count));
+ ASSERT_SUCCESS(olGetDeviceCount(Platform, &Count));
ASSERT_NE(Count, 0lu);
- std::vector<offload_device_handle_t> Devices(Count);
- ASSERT_SUCCESS(offloadDeviceGet(Platform, Count, Devices.data()));
+ std::vector<ol_device_handle_t> Devices(Count);
+ ASSERT_SUCCESS(olGetDevice(Platform, Count, Devices.data()));
for (auto Device : Devices) {
ASSERT_NE(nullptr, Device);
}
}
-TEST_F(offloadDeviceGetTest, SuccessSubsetOfDevices) {
+TEST_F(olGetDeviceTest, SuccessSubsetOfDevices) {
uint32_t Count;
- ASSERT_SUCCESS(offloadDeviceGetCount(Platform, &Count));
+ ASSERT_SUCCESS(olGetDeviceCount(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, Count - 1, Devices.data()));
+ std::vector<ol_device_handle_t> Devices(Count - 1);
+ ASSERT_SUCCESS(olGetDevice(Platform, Count - 1, Devices.data()));
for (auto Device : Devices) {
ASSERT_NE(nullptr, Device);
}
diff --git a/offload/unittests/OffloadAPI/device/olGetDeviceCount.cpp b/offload/unittests/OffloadAPI/device/olGetDeviceCount.cpp
new file mode 100644
index 00000000000000..b76558ebc03448
--- /dev/null
+++ b/offload/unittests/OffloadAPI/device/olGetDeviceCount.cpp
@@ -0,0 +1,29 @@
+//===------- Offload API tests - olGetDeviceCount --------------------===//
+//
+// 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 olGetDeviceCountTest = offloadPlatformTest;
+
+TEST_F(olGetDeviceCountTest, Success) {
+ uint32_t Count = 0;
+ ASSERT_SUCCESS(olGetDeviceCount(Platform, &Count));
+ ASSERT_NE(Count, 0lu);
+}
+
+TEST_F(olGetDeviceCountTest, InvalidNullPlatform) {
+ uint32_t Count = 0;
+ ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, olGetDeviceCount(nullptr, &Count));
+}
+
+TEST_F(olGetDeviceCountTest, InvalidNullPointer) {
+ ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER,
+ olGetDeviceCount(Platform, nullptr));
+}
diff --git a/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp b/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp
new file mode 100644
index 00000000000000..2a09f5a4d0a266
--- /dev/null
+++ b/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp
@@ -0,0 +1,76 @@
+//===------- Offload API tests - olGetDeviceInfo ---------------------===//
+//
+// 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 "olDeviceInfo.hpp"
+#include <gtest/gtest.h>
+#include <offload_api.h>
+
+struct olGetDeviceInfoTest : offloadDeviceTest,
+ ::testing::WithParamInterface<ol_device_info_t> {
+
+ void SetUp() override { RETURN_ON_FATAL_FAILURE(offloadDeviceTest::SetUp()); }
+};
+
+INSTANTIATE_TEST_SUITE_P(
+ , olGetDeviceInfoTest, ::testing::ValuesIn(DeviceQueries),
+ [](const ::testing::TestParamInfo<ol_device_info_t> &info) {
+ std::stringstream ss;
+ ss << info.param;
+ return ss.str();
+ });
+
+TEST_P(olGetDeviceInfoTest, Success) {
+ ol_device_info_t InfoType = GetParam();
+ size_t Size = 0;
+
+ ASSERT_SUCCESS(olGetDeviceInfoSize(Device, InfoType, &Size));
+
+ std::vector<char> InfoData(Size);
+ ASSERT_SUCCESS(olGetDeviceInfo(Device, InfoType, Size, InfoData.data()));
+
+ if (InfoType == OL_DEVICE_INFO_PLATFORM) {
+ auto *ReturnedPlatform =
+ reinterpret_cast<ol_platform_handle_t *>(InfoData.data());
+ ASSERT_EQ(Platform, *ReturnedPlatform);
+ }
+}
+
+TEST_F(olGetDeviceInfoTest, InvalidNullHandleDevice) {
+ ol_device_type_t DeviceType;
+ ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE,
+ olGetDeviceInfo(nullptr, OL_DEVICE_INFO_TYPE,
+ sizeof(ol_device_type_t), &DeviceType));
+}
+
+TEST_F(olGetDeviceInfoTest, InvalidEnumerationInfoType) {
+ ol_device_type_t DeviceType;
+ ASSERT_ERROR(OL_ERRC_INVALID_ENUMERATION,
+ olGetDeviceInfo(Device, OL_DEVICE_INFO_FORCE_UINT32,
+ sizeof(ol_device_type_t), &DeviceType));
+}
+
+TEST_F(olGetDeviceInfoTest, InvalidSizePropSize) {
+ ol_device_type_t DeviceType;
+ ASSERT_ERROR(OL_ERRC_INVALID_SIZE,
+ olGetDeviceInfo(Device, OL_DEVICE_INFO_TYPE, 0, &DeviceType));
+}
+
+TEST_F(olGetDeviceInfoTest, InvalidSizePropSizeSmall) {
+ ol_device_type_t DeviceType;
+ ASSERT_ERROR(OL_ERRC_INVALID_SIZE,
+ olGetDeviceInfo(Device, OL_DEVICE_INFO_TYPE,
+ sizeof(DeviceType) - 1, &DeviceType));
+}
+
+TEST_F(olGetDeviceInfoTest, InvalidNullPointerPropValue) {
+ ol_device_type_t DeviceType;
+ ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER,
+ olGetDeviceInfo(Device, OL_DEVICE_INFO_TYPE, sizeof(DeviceType),
+ nullptr));
+}
diff --git a/offload/unittests/OffloadAPI/device/olGetDeviceInfoSize.cpp b/offload/unittests/OffloadAPI/device/olGetDeviceInfoSize.cpp
new file mode 100644
index 00000000000000..4b1467de97a01c
--- /dev/null
+++ b/offload/unittests/OffloadAPI/device/olGetDeviceInfoSize.cpp
@@ -0,0 +1,58 @@
+//===------- Offload API tests - olGetDeviceInfoSize -----------------===//
+//
+// 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 "olDeviceInfo.hpp"
+
+struct olGetDeviceInfoSizeTest
+ : offloadDeviceTest,
+ ::testing::WithParamInterface<ol_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(
+ , olGetDeviceInfoSizeTest, ::testing::ValuesIn(DeviceQueries),
+ [](const ::testing::TestParamInfo<ol_device_info_t> &info) {
+ std::stringstream ss;
+ ss << info.param;
+ return ss.str();
+ });
+
+TEST_P(olGetDeviceInfoSizeTest, Success) {
+ ol_device_info_t InfoType = GetParam();
+ size_t Size = 0;
+
+ ASSERT_SUCCESS(olGetDeviceInfoSize(Device, InfoType, &Size));
+ auto ExpectedSize = DeviceInfoSizeMap.find(InfoType);
+ if (ExpectedSize != DeviceInfoSizeMap.end()) {
+ ASSERT_EQ(Size, ExpectedSize->second);
+ } else {
+ ASSERT_NE(Size, 0lu);
+ }
+}
+
+TEST_F(olGetDeviceInfoSizeTest, InvalidNullHandle) {
+ size_t Size = 0;
+ ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE,
+ olGetDeviceInfoSize(nullptr, OL_DEVICE_INFO_TYPE, &Size));
+}
+
+TEST_F(olGetDeviceInfoSizeTest, InvalidDeviceInfoEnumeration) {
+ size_t Size = 0;
+ ASSERT_ERROR(OL_ERRC_INVALID_ENUMERATION,
+ olGetDeviceInfoSize(Device, OL_DEVICE_INFO_FORCE_UINT32, &Size));
+}
+
+TEST_F(olGetDeviceInfoSizeTest, InvalidNullPointer) {
+ ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER,
+ olGetDeviceInfoSize(Device, OL_DEVICE_INFO_TYPE, nullptr));
+}
diff --git a/offload/unittests/OffloadAPI/platform/offloadPlatformGet.cpp b/offload/unittests/OffloadAPI/platform/offloadPlatformGet.cpp
deleted file mode 100644
index 37d4b8c62b5ee1..00000000000000
--- a/offload/unittests/OffloadAPI/platform/offloadPlatformGet.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-//===------- 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 "../common/fixtures.hpp"
-#include <gtest/gtest.h>
-#include <offload_api.h>
-
-using offloadPlatformGetTest = offloadTest;
-
-TEST_F(offloadPlatformGetTest, Success) {
- uint32_t PlatformCount;
- ASSERT_SUCCESS(offloadPlatformGetCount(&PlatformCount));
- std::vector<offload_platform_handle_t> Platforms(PlatformCount);
- ASSERT_SUCCESS(offloadPlatformGet(PlatformCount, Platforms.data()));
-}
-
-TEST_F(offloadPlatformGetTest, InvalidNumEntries) {
- uint32_t PlatformCount;
- ASSERT_SUCCESS(offloadPlatformGetCount(&PlatformCount));
- std::vector<offload_platform_handle_t> Platforms(PlatformCount);
- ASSERT_ERROR(
- OFFLOAD_ERRC_INVALID_SIZE,
- offloadPlatformGet(PlatformCount + 1, Platforms.data()));
-}
diff --git a/offload/unittests/OffloadAPI/platform/offloadPlatformGetInfo.cpp b/offload/unittests/OffloadAPI/platform/offloadPlatformGetInfo.cpp
deleted file mode 100644
index 2522b3bf56f77c..00000000000000
--- a/offload/unittests/OffloadAPI/platform/offloadPlatformGetInfo.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-//===------- 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"
-#include "offloadPlatformInfo.hpp"
-
-struct offloadPlatformGetInfoTest
- : offloadPlatformTest,
- ::testing::WithParamInterface<offload_platform_info_t> {};
-
-INSTANTIATE_TEST_SUITE_P(
- offloadPlatformGetInfo, offloadPlatformGetInfoTest,
- ::testing::ValuesIn(PlatformQueries),
- [](const ::testing::TestParamInfo<offload_platform_info_t> &info) {
- std::stringstream ss;
- ss << info.param;
- return ss.str();
- });
-
-TEST_P(offloadPlatformGetInfoTest, Success) {
- size_t Size = 0;
- offload_platform_info_t InfoType = GetParam();
-
- ASSERT_SUCCESS(offloadPlatformGetInfoSize(Platform, InfoType, &Size));
- std::vector<char> InfoData(Size);
- 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) {
- offload_platform_backend_t Backend;
- ASSERT_ERROR(OFFLOAD_ERRC_INVALID_NULL_HANDLE,
- offloadPlatformGetInfo(nullptr, OFFLOAD_PLATFORM_INFO_BACKEND,
- sizeof(Backend), &Backend));
-}
-
-TEST_F(offloadPlatformGetInfoTest, InvalidPlatformInfoEnumeration) {
- offload_platform_backend_t Backend;
- ASSERT_ERROR(OFFLOAD_ERRC_INVALID_ENUMERATION,
- offloadPlatformGetInfo(Platform,
- 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));
-}
-
-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));
-}
-
-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));
-}
diff --git a/offload/unittests/OffloadAPI/platform/offloadPlatformGetInfoSize.cpp b/offload/unittests/OffloadAPI/platform/offloadPlatformGetInfoSize.cpp
deleted file mode 100644
index e90340666d1312..00000000000000
--- a/offload/unittests/OffloadAPI/platform/offloadPlatformGetInfoSize.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-//===------- 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/olGetPlatform.cpp b/offload/unittests/OffloadAPI/platform/olGetPlatform.cpp
new file mode 100644
index 00000000000000..5c80fe2f60fa48
--- /dev/null
+++ b/offload/unittests/OffloadAPI/platform/olGetPlatform.cpp
@@ -0,0 +1,28 @@
+//===------- Offload API tests - olGetPlatform -----------------------===//
+//
+// 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 olGetPlatformTest = offloadTest;
+
+TEST_F(olGetPlatformTest, Success) {
+ uint32_t PlatformCount;
+ ASSERT_SUCCESS(olGetPlatformCount(&PlatformCount));
+ std::vector<ol_platform_handle_t> Platforms(PlatformCount);
+ ASSERT_SUCCESS(olGetPlatform(PlatformCount, Platforms.data()));
+}
+
+TEST_F(olGetPlatformTest, InvalidNumEntries) {
+ uint32_t PlatformCount;
+ ASSERT_SUCCESS(olGetPlatformCount(&PlatformCount));
+ std::vector<ol_platform_handle_t> Platforms(PlatformCount);
+ ASSERT_ERROR(OL_ERRC_INVALID_SIZE,
+ olGetPlatform(PlatformCount + 1, Platforms.data()));
+}
diff --git a/offload/unittests/OffloadAPI/platform/offloadPlatformGetCount.cpp b/offload/unittests/OffloadAPI/platform/olGetPlatformCount.cpp
similarity index 50%
rename from offload/unittests/OffloadAPI/platform/offloadPlatformGetCount.cpp
rename to offload/unittests/OffloadAPI/platform/olGetPlatformCount.cpp
index 94e2f4cad0e5dc..fd30ce042f208a 100644
--- a/offload/unittests/OffloadAPI/platform/offloadPlatformGetCount.cpp
+++ b/offload/unittests/OffloadAPI/platform/olGetPlatformCount.cpp
@@ -1,4 +1,4 @@
-//===------- Offload API tests - offloadPlatformGetCount ------------------===//
+//===------- Offload API tests - olGetPlatformCount ------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -10,14 +10,13 @@
#include <gtest/gtest.h>
#include <offload_api.h>
-using offloadPlatformGetCountTest = offloadTest;
+using olGetPlatformCountTest = offloadTest;
-TEST_F(offloadPlatformGetCountTest, Success) {
+TEST_F(olGetPlatformCountTest, Success) {
uint32_t PlatformCount;
- ASSERT_SUCCESS(offloadPlatformGetCount(&PlatformCount));
+ ASSERT_SUCCESS(olGetPlatformCount(&PlatformCount));
}
-TEST_F(offloadPlatformGetCountTest, InvalidNullPointer) {
- ASSERT_ERROR(OFFLOAD_ERRC_INVALID_NULL_POINTER,
- offloadPlatformGetCount(nullptr));
+TEST_F(olGetPlatformCountTest, InvalidNullPointer) {
+ ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER, olGetPlatformCount(nullptr));
}
diff --git a/offload/unittests/OffloadAPI/platform/olGetPlatformInfo.cpp b/offload/unittests/OffloadAPI/platform/olGetPlatformInfo.cpp
new file mode 100644
index 00000000000000..9f74277450f320
--- /dev/null
+++ b/offload/unittests/OffloadAPI/platform/olGetPlatformInfo.cpp
@@ -0,0 +1,76 @@
+//===------- Offload API tests - olGetPlatformInfo -------------------===//
+//
+// 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 "olPlatformInfo.hpp"
+
+struct olGetPlatformInfoTest
+ : offloadPlatformTest,
+ ::testing::WithParamInterface<ol_platform_info_t> {};
+
+INSTANTIATE_TEST_SUITE_P(
+ olGetPlatformInfo, olGetPlatformInfoTest,
+ ::testing::ValuesIn(PlatformQueries),
+ [](const ::testing::TestParamInfo<ol_platform_info_t> &info) {
+ std::stringstream ss;
+ ss << info.param;
+ return ss.str();
+ });
+
+TEST_P(olGetPlatformInfoTest, Success) {
+ size_t Size = 0;
+ ol_platform_info_t InfoType = GetParam();
+
+ ASSERT_SUCCESS(olGetPlatformInfoSize(Platform, InfoType, &Size));
+ std::vector<char> InfoData(Size);
+ ASSERT_SUCCESS(olGetPlatformInfo(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(olGetPlatformInfoTest, InvalidNullHandle) {
+ ol_platform_backend_t Backend;
+ ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE,
+ olGetPlatformInfo(nullptr, OL_PLATFORM_INFO_BACKEND,
+ sizeof(Backend), &Backend));
+}
+
+TEST_F(olGetPlatformInfoTest, InvalidPlatformInfoEnumeration) {
+ ol_platform_backend_t Backend;
+ ASSERT_ERROR(OL_ERRC_INVALID_ENUMERATION,
+ olGetPlatformInfo(Platform, OL_PLATFORM_INFO_FORCE_UINT32,
+ sizeof(Backend), &Backend));
+}
+
+TEST_F(olGetPlatformInfoTest, InvalidSizeZero) {
+ ol_platform_backend_t Backend;
+ ASSERT_ERROR(
+ OL_ERRC_INVALID_SIZE,
+ olGetPlatformInfo(Platform, OL_PLATFORM_INFO_BACKEND, 0, &Backend));
+}
+
+TEST_F(olGetPlatformInfoTest, InvalidSizeSmall) {
+ ol_platform_backend_t Backend;
+ ASSERT_ERROR(OL_ERRC_INVALID_SIZE,
+ olGetPlatformInfo(Platform, OL_PLATFORM_INFO_BACKEND,
+ sizeof(Backend) - 1, &Backend));
+}
+
+TEST_F(olGetPlatformInfoTest, InvalidNullPointerPropValue) {
+ ol_platform_backend_t Backend;
+ ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER,
+ olGetPlatformInfo(Platform, OL_PLATFORM_INFO_BACKEND,
+ sizeof(Backend), nullptr));
+}
diff --git a/offload/unittests/OffloadAPI/platform/olGetPlatformInfoSize.cpp b/offload/unittests/OffloadAPI/platform/olGetPlatformInfoSize.cpp
new file mode 100644
index 00000000000000..80f700dc33e816
--- /dev/null
+++ b/offload/unittests/OffloadAPI/platform/olGetPlatformInfoSize.cpp
@@ -0,0 +1,57 @@
+//===------- Offload API tests - olGetPlatformInfoSize ---------------===//
+//
+// 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 "olPlatformInfo.hpp"
+
+struct olGetPlatformInfoSizeTest
+ : offloadPlatformTest,
+ ::testing::WithParamInterface<ol_platform_info_t> {};
+
+INSTANTIATE_TEST_SUITE_P(
+ olGetPlatformInfoSize, olGetPlatformInfoSizeTest,
+ ::testing::ValuesIn(PlatformQueries),
+ [](const ::testing::TestParamInfo<ol_platform_info_t> &info) {
+ std::stringstream ss;
+ ss << info.param;
+ return ss.str();
+ });
+
+TEST_P(olGetPlatformInfoSizeTest, Success) {
+ size_t Size = 0;
+ ol_platform_info_t InfoType = GetParam();
+
+ ASSERT_SUCCESS(olGetPlatformInfoSize(Platform, InfoType, &Size));
+ auto ExpectedSize = PlatformInfoSizeMap.find(InfoType);
+ if (ExpectedSize != PlatformInfoSizeMap.end()) {
+ ASSERT_EQ(Size, ExpectedSize->second);
+ } else {
+ ASSERT_NE(Size, 0lu);
+ }
+}
+
+TEST_F(olGetPlatformInfoSizeTest, InvalidNullHandle) {
+ size_t Size = 0;
+ ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE,
+ olGetPlatformInfoSize(nullptr, OL_PLATFORM_INFO_BACKEND, &Size));
+}
+
+TEST_F(olGetPlatformInfoSizeTest, InvalidPlatformInfoEnumeration) {
+ size_t Size = 0;
+ ASSERT_ERROR(
+ OL_ERRC_INVALID_ENUMERATION,
+ olGetPlatformInfoSize(Platform, OL_PLATFORM_INFO_FORCE_UINT32, &Size));
+}
+
+TEST_F(olGetPlatformInfoSizeTest, InvalidNullPointer) {
+ ASSERT_ERROR(
+ OL_ERRC_INVALID_NULL_POINTER,
+ olGetPlatformInfoSize(Platform, OL_PLATFORM_INFO_BACKEND, nullptr));
+}
diff --git a/offload/unittests/OffloadAPI/platform/offloadPlatformInfo.hpp b/offload/unittests/OffloadAPI/platform/olPlatformInfo.hpp
similarity index 55%
rename from offload/unittests/OffloadAPI/platform/offloadPlatformInfo.hpp
rename to offload/unittests/OffloadAPI/platform/olPlatformInfo.hpp
index c4a0fc21b33d05..d49cdb90d321ad 100644
--- a/offload/unittests/OffloadAPI/platform/offloadPlatformInfo.hpp
+++ b/offload/unittests/OffloadAPI/platform/olPlatformInfo.hpp
@@ -11,11 +11,10 @@
// 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::vector<ol_platform_info_t> PlatformQueries = {
+ OL_PLATFORM_INFO_NAME, OL_PLATFORM_INFO_VENDOR_NAME,
+ OL_PLATFORM_INFO_VERSION, OL_PLATFORM_INFO_BACKEND};
-inline std::unordered_map<offload_platform_info_t, size_t> PlatformInfoSizeMap =
- {
- {OFFLOAD_PLATFORM_INFO_BACKEND, sizeof(offload_platform_backend_t)},
+inline std::unordered_map<ol_platform_info_t, size_t> PlatformInfoSizeMap = {
+ {OL_PLATFORM_INFO_BACKEND, sizeof(ol_platform_backend_t)},
};
>From 234f3108f76e4400a5446fa7fa4336b0aefb8f3c Mon Sep 17 00:00:00 2001
From: Callum Fare <callum at codeplay.com>
Date: Thu, 31 Oct 2024 12:22:02 +0000
Subject: [PATCH 20/24] Rename new offload library and try to match LLVM style
---
offload/CMakeLists.txt | 2 +-
.../{new-api => liboffload}/API/APIDefs.td | 0
.../API/CMakeLists.txt | 13 ++++----
offload/{new-api => liboffload}/API/Common.td | 0
offload/{new-api => liboffload}/API/Device.td | 0
.../{new-api => liboffload}/API/OffloadAPI.td | 0
.../{new-api => liboffload}/API/Platform.td | 0
offload/{new-api => liboffload}/API/README.md | 0
offload/liboffload/CMakeLists.txt | 32 +++++++++++++++++++
offload/{new-api => liboffload}/README.md | 0
offload/liboffload/exports | 6 ++++
.../include/OffloadImpl.hpp} | 2 +-
.../include/generated/OffloadAPI.h} | 0
.../include/generated/OffloadEntryPoints.inc} | 0
.../include/generated/OffloadFuncs.inc} | 0
.../generated/OffloadImplFuncDecls.inc} | 0
.../include/generated/OffloadPrint.hpp} | 2 +-
.../src/Helpers.hpp} | 2 +-
.../src/OffloadImpl.cpp} | 6 ++--
.../src/OffloadLib.cpp} | 10 +++---
offload/new-api/CMakeLists.txt | 30 -----------------
offload/new-api/include/offload_exports | 25 ---------------
offload/tools/offload-tblgen/PrintGen.cpp | 2 +-
offload/unittests/OffloadAPI/CMakeLists.txt | 4 +--
.../{environment.cpp => Environment.cpp} | 6 ++--
.../{environment.hpp => Environment.hpp} | 2 +-
.../common/{fixtures.hpp => Fixtures.hpp} | 6 ++--
.../OffloadAPI/device/olGetDevice.cpp | 4 +--
.../OffloadAPI/device/olGetDeviceCount.cpp | 4 +--
.../OffloadAPI/device/olGetDeviceInfo.cpp | 4 +--
.../OffloadAPI/device/olGetDeviceInfoSize.cpp | 4 +--
.../OffloadAPI/platform/olGetPlatform.cpp | 4 +--
.../platform/olGetPlatformCount.cpp | 4 +--
.../OffloadAPI/platform/olGetPlatformInfo.cpp | 4 +--
.../platform/olGetPlatformInfoSize.cpp | 4 +--
35 files changed, 82 insertions(+), 100 deletions(-)
rename offload/{new-api => liboffload}/API/APIDefs.td (100%)
rename offload/{new-api => liboffload}/API/CMakeLists.txt (72%)
rename offload/{new-api => liboffload}/API/Common.td (100%)
rename offload/{new-api => liboffload}/API/Device.td (100%)
rename offload/{new-api => liboffload}/API/OffloadAPI.td (100%)
rename offload/{new-api => liboffload}/API/Platform.td (100%)
rename offload/{new-api => liboffload}/API/README.md (100%)
create mode 100644 offload/liboffload/CMakeLists.txt
rename offload/{new-api => liboffload}/README.md (100%)
create mode 100644 offload/liboffload/exports
rename offload/{new-api/include/offload_impl.hpp => liboffload/include/OffloadImpl.hpp} (99%)
rename offload/{new-api/include/offload_api.h => liboffload/include/generated/OffloadAPI.h} (100%)
rename offload/{new-api/include/offload_entry_points.inc => liboffload/include/generated/OffloadEntryPoints.inc} (100%)
rename offload/{new-api/include/offload_funcs.inc => liboffload/include/generated/OffloadFuncs.inc} (100%)
rename offload/{new-api/include/offload_impl_func_decls.inc => liboffload/include/generated/OffloadImplFuncDecls.inc} (100%)
rename offload/{new-api/include/offload_print.hpp => liboffload/include/generated/OffloadPrint.hpp} (99%)
rename offload/{new-api/src/helpers.hpp => liboffload/src/Helpers.hpp} (99%)
rename offload/{new-api/src/offload_impl.cpp => liboffload/src/OffloadImpl.cpp} (99%)
rename offload/{new-api/src/offload_lib.cpp => liboffload/src/OffloadLib.cpp} (87%)
delete mode 100644 offload/new-api/CMakeLists.txt
delete mode 100644 offload/new-api/include/offload_exports
rename offload/unittests/OffloadAPI/common/{environment.cpp => Environment.cpp} (97%)
rename offload/unittests/OffloadAPI/common/{environment.hpp => Environment.hpp} (95%)
rename offload/unittests/OffloadAPI/common/{fixtures.hpp => Fixtures.hpp} (96%)
diff --git a/offload/CMakeLists.txt b/offload/CMakeLists.txt
index 27c9de509c436e..af2e07d5147216 100644
--- a/offload/CMakeLists.txt
+++ b/offload/CMakeLists.txt
@@ -352,7 +352,7 @@ add_subdirectory(tools)
add_subdirectory(src)
add_subdirectory(tools/offload-tblgen)
-add_subdirectory(new-api)
+add_subdirectory(liboffload)
# Add tests.
add_subdirectory(test)
diff --git a/offload/new-api/API/APIDefs.td b/offload/liboffload/API/APIDefs.td
similarity index 100%
rename from offload/new-api/API/APIDefs.td
rename to offload/liboffload/API/APIDefs.td
diff --git a/offload/new-api/API/CMakeLists.txt b/offload/liboffload/API/CMakeLists.txt
similarity index 72%
rename from offload/new-api/API/CMakeLists.txt
rename to offload/liboffload/API/CMakeLists.txt
index 2f12b48133fbcc..7c93c220338853 100644
--- a/offload/new-api/API/CMakeLists.txt
+++ b/offload/liboffload/API/CMakeLists.txt
@@ -6,19 +6,18 @@ find_program(CLANG_FORMAT clang-format PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT
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)
+ tablegen(OFFLOAD OffloadAPI.h -gen-api)
+ tablegen(OFFLOAD OffloadFuncs.inc -gen-func-names)
+ tablegen(OFFLOAD OffloadImplFuncDecls.inc -gen-impl-func-decls)
+ tablegen(OFFLOAD OffloadPrint.hpp -gen-print-header)
+ tablegen(OFFLOAD OffloadExports -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")
+ -E copy_if_different ${OFFLOAD_GENERATED_FILES} "${CMAKE_CURRENT_SOURCE_DIR}/../include/generated")
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\
diff --git a/offload/new-api/API/Common.td b/offload/liboffload/API/Common.td
similarity index 100%
rename from offload/new-api/API/Common.td
rename to offload/liboffload/API/Common.td
diff --git a/offload/new-api/API/Device.td b/offload/liboffload/API/Device.td
similarity index 100%
rename from offload/new-api/API/Device.td
rename to offload/liboffload/API/Device.td
diff --git a/offload/new-api/API/OffloadAPI.td b/offload/liboffload/API/OffloadAPI.td
similarity index 100%
rename from offload/new-api/API/OffloadAPI.td
rename to offload/liboffload/API/OffloadAPI.td
diff --git a/offload/new-api/API/Platform.td b/offload/liboffload/API/Platform.td
similarity index 100%
rename from offload/new-api/API/Platform.td
rename to offload/liboffload/API/Platform.td
diff --git a/offload/new-api/API/README.md b/offload/liboffload/API/README.md
similarity index 100%
rename from offload/new-api/API/README.md
rename to offload/liboffload/API/README.md
diff --git a/offload/liboffload/CMakeLists.txt b/offload/liboffload/CMakeLists.txt
new file mode 100644
index 00000000000000..27ba9e93c36753
--- /dev/null
+++ b/offload/liboffload/CMakeLists.txt
@@ -0,0 +1,32 @@
+add_subdirectory(API)
+
+add_llvm_library(LLVMOffload SHARED
+ src/OffloadLib.cpp
+ src/OffloadImpl.cpp)
+
+foreach(plugin IN LISTS LIBOMPTARGET_PLUGINS_TO_BUILD)
+ target_link_libraries(LLVMOffload PRIVATE omptarget.rtl.${plugin})
+endforeach()
+
+if(LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
+ target_link_libraries(LLVMOffload PRIVATE "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports")
+endif()
+
+target_include_directories(LLVMOffload PUBLIC
+ ${CMAKE_CURRENT_BINARY_DIR}/../include
+ ${CMAKE_CURRENT_SOURCE_DIR}/include
+ ${CMAKE_CURRENT_SOURCE_DIR}/include/generated
+ ${CMAKE_CURRENT_SOURCE_DIR}/../include
+ ${CMAKE_CURRENT_SOURCE_DIR}/../plugins-nextgen/common/include)
+
+target_compile_options(LLVMOffload PRIVATE ${offload_compile_flags})
+target_link_options(LLVMOffload PRIVATE ${offload_link_flags})
+
+set_target_properties(LLVMOffload PROPERTIES
+ POSITION_INDEPENDENT_CODE ON
+ INSTALL_RPATH "$ORIGIN"
+ BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/..")
+install(TARGETS LLVMOffload LIBRARY COMPONENT LLVMOffload DESTINATION "${OFFLOAD_INSTALL_LIBDIR}")
+
+install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/OffloadAPI.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/offload)
+install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/OffloadPrint.hpp DESTINATION ${CMAKE_INSTALL_PREFIX}/include/offload)
diff --git a/offload/new-api/README.md b/offload/liboffload/README.md
similarity index 100%
rename from offload/new-api/README.md
rename to offload/liboffload/README.md
diff --git a/offload/liboffload/exports b/offload/liboffload/exports
new file mode 100644
index 00000000000000..168341aa7d9380
--- /dev/null
+++ b/offload/liboffload/exports
@@ -0,0 +1,6 @@
+VERS1.0 {
+global:
+ ol*;
+local:
+ *;
+};
diff --git a/offload/new-api/include/offload_impl.hpp b/offload/liboffload/include/OffloadImpl.hpp
similarity index 99%
rename from offload/new-api/include/offload_impl.hpp
rename to offload/liboffload/include/OffloadImpl.hpp
index 80966ccf234f06..6d745095f3105a 100644
--- a/offload/new-api/include/offload_impl.hpp
+++ b/offload/liboffload/include/OffloadImpl.hpp
@@ -7,9 +7,9 @@
//===----------------------------------------------------------------------===//
#pragma once
+#include <OffloadAPI.h>
#include <iostream>
#include <memory>
-#include <offload_api.h>
#include <optional>
#include <set>
#include <string>
diff --git a/offload/new-api/include/offload_api.h b/offload/liboffload/include/generated/OffloadAPI.h
similarity index 100%
rename from offload/new-api/include/offload_api.h
rename to offload/liboffload/include/generated/OffloadAPI.h
diff --git a/offload/new-api/include/offload_entry_points.inc b/offload/liboffload/include/generated/OffloadEntryPoints.inc
similarity index 100%
rename from offload/new-api/include/offload_entry_points.inc
rename to offload/liboffload/include/generated/OffloadEntryPoints.inc
diff --git a/offload/new-api/include/offload_funcs.inc b/offload/liboffload/include/generated/OffloadFuncs.inc
similarity index 100%
rename from offload/new-api/include/offload_funcs.inc
rename to offload/liboffload/include/generated/OffloadFuncs.inc
diff --git a/offload/new-api/include/offload_impl_func_decls.inc b/offload/liboffload/include/generated/OffloadImplFuncDecls.inc
similarity index 100%
rename from offload/new-api/include/offload_impl_func_decls.inc
rename to offload/liboffload/include/generated/OffloadImplFuncDecls.inc
diff --git a/offload/new-api/include/offload_print.hpp b/offload/liboffload/include/generated/OffloadPrint.hpp
similarity index 99%
rename from offload/new-api/include/offload_print.hpp
rename to offload/liboffload/include/generated/OffloadPrint.hpp
index d2136143fd20ff..8981bb054a4cb1 100644
--- a/offload/new-api/include/offload_print.hpp
+++ b/offload/liboffload/include/generated/OffloadPrint.hpp
@@ -10,7 +10,7 @@
#pragma once
-#include <offload_api.h>
+#include <OffloadAPI.h>
#include <ostream>
template <typename T>
diff --git a/offload/new-api/src/helpers.hpp b/offload/liboffload/src/Helpers.hpp
similarity index 99%
rename from offload/new-api/src/helpers.hpp
rename to offload/liboffload/src/Helpers.hpp
index 8aa8e319b278bd..d003d302524625 100644
--- a/offload/new-api/src/helpers.hpp
+++ b/offload/liboffload/src/Helpers.hpp
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
-#include "offload_api.h"
+#include "OffloadAPI.h"
#include <cstring>
diff --git a/offload/new-api/src/offload_impl.cpp b/offload/liboffload/src/OffloadImpl.cpp
similarity index 99%
rename from offload/new-api/src/offload_impl.cpp
rename to offload/liboffload/src/OffloadImpl.cpp
index c9f20440dc266c..1137c0845d78f7 100644
--- a/offload/new-api/src/offload_impl.cpp
+++ b/offload/liboffload/src/OffloadImpl.cpp
@@ -11,11 +11,11 @@
//
//===----------------------------------------------------------------------===//
-#include "offload_impl.hpp"
+#include "OffloadImpl.hpp"
+#include "Helpers.hpp"
#include "PluginManager.h"
-#include "helpers.hpp"
#include "llvm/Support/FormatVariadic.h"
-#include <offload_api.h>
+#include <OffloadAPI.h>
#include <mutex>
diff --git a/offload/new-api/src/offload_lib.cpp b/offload/liboffload/src/OffloadLib.cpp
similarity index 87%
rename from offload/new-api/src/offload_lib.cpp
rename to offload/liboffload/src/OffloadLib.cpp
index 29cb614844875a..37876713212c98 100644
--- a/offload/new-api/src/offload_lib.cpp
+++ b/offload/liboffload/src/OffloadLib.cpp
@@ -10,9 +10,9 @@
//
//===----------------------------------------------------------------------===//
-#include "offload_impl.hpp"
-#include <offload_api.h>
-#include <offload_print.hpp>
+#include "OffloadImpl.hpp"
+#include <OffloadAPI.h>
+#include <OffloadPrint.hpp>
#include <iostream>
@@ -38,7 +38,7 @@ OffloadConfig &offloadConfig() {
// Pull in the declarations for the implementation funtions. The actual entry
// points in this file wrap these.
-#include "offload_impl_func_decls.inc"
+#include "OffloadImplFuncDecls.inc"
// Pull in the tablegen'd entry point definitions.
-#include "offload_entry_points.inc"
+#include "OffloadEntryPoints.inc"
diff --git a/offload/new-api/CMakeLists.txt b/offload/new-api/CMakeLists.txt
deleted file mode 100644
index a79b88303bb4d7..00000000000000
--- a/offload/new-api/CMakeLists.txt
+++ /dev/null
@@ -1,30 +0,0 @@
-add_subdirectory(API)
-
-add_llvm_library(offload_new SHARED
- src/offload_lib.cpp
- src/offload_impl.cpp)
-
-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_SOURCE_DIR}/include/offload_exports")
-endif()
-
-target_include_directories(offload_new PUBLIC
- ${CMAKE_CURRENT_BINARY_DIR}/../include
- ${CMAKE_CURRENT_SOURCE_DIR}/include
- ${CMAKE_CURRENT_SOURCE_DIR}/../include
- ${CMAKE_CURRENT_SOURCE_DIR}/../plugins-nextgen/common/include)
-
-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
- 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_SOURCE_DIR}/include/offload_api.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/offload)
diff --git a/offload/new-api/include/offload_exports b/offload/new-api/include/offload_exports
deleted file mode 100644
index a07a4a4bc2029a..00000000000000
--- a/offload/new-api/include/offload_exports
+++ /dev/null
@@ -1,25 +0,0 @@
-VERS1.0 {
-global:
- olInit;
- olShutDown;
- olGetPlatform;
- olGetPlatformCount;
- olGetPlatformInfo;
- olGetPlatformInfoSize;
- olGetDeviceCount;
- olGetDevice;
- olGetDeviceInfo;
- olGetDeviceInfoSize;
- olInitWithCodeLoc;
- olShutDownWithCodeLoc;
- olGetPlatformWithCodeLoc;
- olGetPlatformCountWithCodeLoc;
- olGetPlatformInfoWithCodeLoc;
- olGetPlatformInfoSizeWithCodeLoc;
- olGetDeviceCountWithCodeLoc;
- olGetDeviceWithCodeLoc;
- olGetDeviceInfoWithCodeLoc;
- olGetDeviceInfoSizeWithCodeLoc;
-local:
- *;
-};
diff --git a/offload/tools/offload-tblgen/PrintGen.cpp b/offload/tools/offload-tblgen/PrintGen.cpp
index 9a288139dc7a2d..518213234c80b1 100644
--- a/offload/tools/offload-tblgen/PrintGen.cpp
+++ b/offload/tools/offload-tblgen/PrintGen.cpp
@@ -157,7 +157,7 @@ void EmitOffloadPrintHeader(RecordKeeper &Records, raw_ostream &OS) {
#pragma once
-#include <offload_api.h>
+#include <OffloadAPI.h>
#include <ostream>
diff --git a/offload/unittests/OffloadAPI/CMakeLists.txt b/offload/unittests/OffloadAPI/CMakeLists.txt
index c5d4473d39dc45..033ee2b6ec746a 100644
--- a/offload/unittests/OffloadAPI/CMakeLists.txt
+++ b/offload/unittests/OffloadAPI/CMakeLists.txt
@@ -1,8 +1,8 @@
-set(PLUGINS_TEST_COMMON offload_new)
+set(PLUGINS_TEST_COMMON LLVMOffload)
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}/common/Environment.cpp
${CMAKE_CURRENT_SOURCE_DIR}/platform/olGetPlatform.cpp
${CMAKE_CURRENT_SOURCE_DIR}/platform/olGetPlatformCount.cpp
${CMAKE_CURRENT_SOURCE_DIR}/platform/olGetPlatformInfo.cpp
diff --git a/offload/unittests/OffloadAPI/common/environment.cpp b/offload/unittests/OffloadAPI/common/Environment.cpp
similarity index 97%
rename from offload/unittests/OffloadAPI/common/environment.cpp
rename to offload/unittests/OffloadAPI/common/Environment.cpp
index f1763c706d0851..f07a66cda21892 100644
--- a/offload/unittests/OffloadAPI/common/environment.cpp
+++ b/offload/unittests/OffloadAPI/common/Environment.cpp
@@ -6,10 +6,10 @@
//
//===----------------------------------------------------------------------===//
-#include "environment.hpp"
-#include "fixtures.hpp"
+#include "Environment.hpp"
+#include "Fixtures.hpp"
#include "llvm/Support/CommandLine.h"
-#include <offload_api.h>
+#include <OffloadAPI.h>
using namespace llvm;
diff --git a/offload/unittests/OffloadAPI/common/environment.hpp b/offload/unittests/OffloadAPI/common/Environment.hpp
similarity index 95%
rename from offload/unittests/OffloadAPI/common/environment.hpp
rename to offload/unittests/OffloadAPI/common/Environment.hpp
index 6fb9291ff88149..6dba2381eb0b71 100644
--- a/offload/unittests/OffloadAPI/common/environment.hpp
+++ b/offload/unittests/OffloadAPI/common/Environment.hpp
@@ -8,8 +8,8 @@
#pragma once
+#include <OffloadAPI.h>
#include <gtest/gtest.h>
-#include <offload_api.h>
namespace TestEnvironment {
const std::vector<ol_platform_handle_t> &getPlatforms();
diff --git a/offload/unittests/OffloadAPI/common/fixtures.hpp b/offload/unittests/OffloadAPI/common/Fixtures.hpp
similarity index 96%
rename from offload/unittests/OffloadAPI/common/fixtures.hpp
rename to offload/unittests/OffloadAPI/common/Fixtures.hpp
index 5d93c4cb2e5ac7..ec506418bea070 100644
--- a/offload/unittests/OffloadAPI/common/fixtures.hpp
+++ b/offload/unittests/OffloadAPI/common/Fixtures.hpp
@@ -6,11 +6,11 @@
//
//===----------------------------------------------------------------------===//
+#include <OffloadAPI.h>
+#include <OffloadPrint.hpp>
#include <gtest/gtest.h>
-#include <offload_api.h>
-#include <offload_print.hpp>
-#include "environment.hpp"
+#include "Environment.hpp"
#pragma once
diff --git a/offload/unittests/OffloadAPI/device/olGetDevice.cpp b/offload/unittests/OffloadAPI/device/olGetDevice.cpp
index 5d115b7326d202..217e7276052978 100644
--- a/offload/unittests/OffloadAPI/device/olGetDevice.cpp
+++ b/offload/unittests/OffloadAPI/device/olGetDevice.cpp
@@ -6,9 +6,9 @@
//
//===----------------------------------------------------------------------===//
-#include "../common/fixtures.hpp"
+#include "../common/Fixtures.hpp"
+#include <OffloadAPI.h>
#include <gtest/gtest.h>
-#include <offload_api.h>
using olGetDeviceTest = offloadPlatformTest;
diff --git a/offload/unittests/OffloadAPI/device/olGetDeviceCount.cpp b/offload/unittests/OffloadAPI/device/olGetDeviceCount.cpp
index b76558ebc03448..4f94d89c387746 100644
--- a/offload/unittests/OffloadAPI/device/olGetDeviceCount.cpp
+++ b/offload/unittests/OffloadAPI/device/olGetDeviceCount.cpp
@@ -6,9 +6,9 @@
//
//===----------------------------------------------------------------------===//
-#include "../common/fixtures.hpp"
+#include "../common/Fixtures.hpp"
+#include <OffloadAPI.h>
#include <gtest/gtest.h>
-#include <offload_api.h>
using olGetDeviceCountTest = offloadPlatformTest;
diff --git a/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp b/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp
index 2a09f5a4d0a266..c936802fb1e4d6 100644
--- a/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp
+++ b/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp
@@ -6,10 +6,10 @@
//
//===----------------------------------------------------------------------===//
-#include "../common/fixtures.hpp"
+#include "../common/Fixtures.hpp"
#include "olDeviceInfo.hpp"
+#include <OffloadAPI.h>
#include <gtest/gtest.h>
-#include <offload_api.h>
struct olGetDeviceInfoTest : offloadDeviceTest,
::testing::WithParamInterface<ol_device_info_t> {
diff --git a/offload/unittests/OffloadAPI/device/olGetDeviceInfoSize.cpp b/offload/unittests/OffloadAPI/device/olGetDeviceInfoSize.cpp
index 4b1467de97a01c..9e792d1c3e25ef 100644
--- a/offload/unittests/OffloadAPI/device/olGetDeviceInfoSize.cpp
+++ b/offload/unittests/OffloadAPI/device/olGetDeviceInfoSize.cpp
@@ -6,9 +6,9 @@
//
//===----------------------------------------------------------------------===//
-#include <offload_api.h>
+#include <OffloadAPI.h>
-#include "../common/fixtures.hpp"
+#include "../common/Fixtures.hpp"
#include "olDeviceInfo.hpp"
struct olGetDeviceInfoSizeTest
diff --git a/offload/unittests/OffloadAPI/platform/olGetPlatform.cpp b/offload/unittests/OffloadAPI/platform/olGetPlatform.cpp
index 5c80fe2f60fa48..4a2f9e8ac77414 100644
--- a/offload/unittests/OffloadAPI/platform/olGetPlatform.cpp
+++ b/offload/unittests/OffloadAPI/platform/olGetPlatform.cpp
@@ -6,9 +6,9 @@
//
//===----------------------------------------------------------------------===//
-#include "../common/fixtures.hpp"
+#include "../common/Fixtures.hpp"
+#include <OffloadAPI.h>
#include <gtest/gtest.h>
-#include <offload_api.h>
using olGetPlatformTest = offloadTest;
diff --git a/offload/unittests/OffloadAPI/platform/olGetPlatformCount.cpp b/offload/unittests/OffloadAPI/platform/olGetPlatformCount.cpp
index fd30ce042f208a..15b4b6abcd70da 100644
--- a/offload/unittests/OffloadAPI/platform/olGetPlatformCount.cpp
+++ b/offload/unittests/OffloadAPI/platform/olGetPlatformCount.cpp
@@ -6,9 +6,9 @@
//
//===----------------------------------------------------------------------===//
-#include "../common/fixtures.hpp"
+#include "../common/Fixtures.hpp"
+#include <OffloadAPI.h>
#include <gtest/gtest.h>
-#include <offload_api.h>
using olGetPlatformCountTest = offloadTest;
diff --git a/offload/unittests/OffloadAPI/platform/olGetPlatformInfo.cpp b/offload/unittests/OffloadAPI/platform/olGetPlatformInfo.cpp
index 9f74277450f320..c646bdc50b7da1 100644
--- a/offload/unittests/OffloadAPI/platform/olGetPlatformInfo.cpp
+++ b/offload/unittests/OffloadAPI/platform/olGetPlatformInfo.cpp
@@ -6,9 +6,9 @@
//
//===----------------------------------------------------------------------===//
-#include <offload_api.h>
+#include <OffloadAPI.h>
-#include "../common/fixtures.hpp"
+#include "../common/Fixtures.hpp"
#include "olPlatformInfo.hpp"
struct olGetPlatformInfoTest
diff --git a/offload/unittests/OffloadAPI/platform/olGetPlatformInfoSize.cpp b/offload/unittests/OffloadAPI/platform/olGetPlatformInfoSize.cpp
index 80f700dc33e816..7c9274082e8e49 100644
--- a/offload/unittests/OffloadAPI/platform/olGetPlatformInfoSize.cpp
+++ b/offload/unittests/OffloadAPI/platform/olGetPlatformInfoSize.cpp
@@ -6,9 +6,9 @@
//
//===----------------------------------------------------------------------===//
-#include <offload_api.h>
+#include <OffloadAPI.h>
-#include "../common/fixtures.hpp"
+#include "../common/Fixtures.hpp"
#include "olPlatformInfo.hpp"
struct olGetPlatformInfoSizeTest
>From 5041d48e1d9efe89bde0bdb8c5e2068a2e9d584e Mon Sep 17 00:00:00 2001
From: Callum Fare <callum at codeplay.com>
Date: Thu, 31 Oct 2024 14:53:55 +0000
Subject: [PATCH 21/24] Fix missing tablegen, tidy Offload tests
---
offload/liboffload/API/CMakeLists.txt | 2 +-
offload/unittests/OffloadAPI/common/Fixtures.hpp | 3 +--
offload/unittests/OffloadAPI/device/olGetDevice.cpp | 8 +++++---
offload/unittests/OffloadAPI/device/olGetDeviceCount.cpp | 1 -
4 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/offload/liboffload/API/CMakeLists.txt b/offload/liboffload/API/CMakeLists.txt
index 7c93c220338853..8fd6cb539374a5 100644
--- a/offload/liboffload/API/CMakeLists.txt
+++ b/offload/liboffload/API/CMakeLists.txt
@@ -7,10 +7,10 @@ if (CLANG_FORMAT)
set(LLVM_TARGET_DEFINITIONS ${CMAKE_CURRENT_SOURCE_DIR}/OffloadAPI.td)
tablegen(OFFLOAD OffloadAPI.h -gen-api)
+ tablegen(OFFLOAD OffloadEntryPoints.inc -gen-entry-points)
tablegen(OFFLOAD OffloadFuncs.inc -gen-func-names)
tablegen(OFFLOAD OffloadImplFuncDecls.inc -gen-impl-func-decls)
tablegen(OFFLOAD OffloadPrint.hpp -gen-print-header)
- tablegen(OFFLOAD OffloadExports -gen-exports)
set(OFFLOAD_GENERATED_FILES ${TABLEGEN_OUTPUT})
add_public_tablegen_target(OffloadGenerate)
diff --git a/offload/unittests/OffloadAPI/common/Fixtures.hpp b/offload/unittests/OffloadAPI/common/Fixtures.hpp
index ec506418bea070..410a435dee1b5f 100644
--- a/offload/unittests/OffloadAPI/common/Fixtures.hpp
+++ b/offload/unittests/OffloadAPI/common/Fixtures.hpp
@@ -55,9 +55,8 @@ struct offloadDeviceTest : offloadPlatformTest {
uint32_t NumDevices;
ASSERT_SUCCESS(olGetDeviceCount(Platform, &NumDevices));
- if (NumDevices == 0) {
+ if (NumDevices == 0)
GTEST_SKIP() << "No available devices on this platform.";
- }
ASSERT_SUCCESS(olGetDevice(Platform, 1, &Device));
}
diff --git a/offload/unittests/OffloadAPI/device/olGetDevice.cpp b/offload/unittests/OffloadAPI/device/olGetDevice.cpp
index 217e7276052978..68d4682dd3351c 100644
--- a/offload/unittests/OffloadAPI/device/olGetDevice.cpp
+++ b/offload/unittests/OffloadAPI/device/olGetDevice.cpp
@@ -15,7 +15,9 @@ using olGetDeviceTest = offloadPlatformTest;
TEST_F(olGetDeviceTest, Success) {
uint32_t Count = 0;
ASSERT_SUCCESS(olGetDeviceCount(Platform, &Count));
- ASSERT_NE(Count, 0lu);
+ if (Count == 0)
+ GTEST_SKIP() << "No available devices on this platform.";
+
std::vector<ol_device_handle_t> Devices(Count);
ASSERT_SUCCESS(olGetDevice(Platform, Count, Devices.data()));
for (auto Device : Devices) {
@@ -26,9 +28,9 @@ TEST_F(olGetDeviceTest, Success) {
TEST_F(olGetDeviceTest, SuccessSubsetOfDevices) {
uint32_t Count;
ASSERT_SUCCESS(olGetDeviceCount(Platform, &Count));
- if (Count < 2) {
+ if (Count < 2)
GTEST_SKIP() << "Only one device is available on this platform.";
- }
+
std::vector<ol_device_handle_t> Devices(Count - 1);
ASSERT_SUCCESS(olGetDevice(Platform, Count - 1, Devices.data()));
for (auto Device : Devices) {
diff --git a/offload/unittests/OffloadAPI/device/olGetDeviceCount.cpp b/offload/unittests/OffloadAPI/device/olGetDeviceCount.cpp
index 4f94d89c387746..ef377d671bf60d 100644
--- a/offload/unittests/OffloadAPI/device/olGetDeviceCount.cpp
+++ b/offload/unittests/OffloadAPI/device/olGetDeviceCount.cpp
@@ -15,7 +15,6 @@ using olGetDeviceCountTest = offloadPlatformTest;
TEST_F(olGetDeviceCountTest, Success) {
uint32_t Count = 0;
ASSERT_SUCCESS(olGetDeviceCount(Platform, &Count));
- ASSERT_NE(Count, 0lu);
}
TEST_F(olGetDeviceCountTest, InvalidNullPlatform) {
>From b746a6326f65578b74be485be06c5600016e0ef2 Mon Sep 17 00:00:00 2001
From: Callum Fare <callum at codeplay.com>
Date: Fri, 1 Nov 2024 16:56:02 +0000
Subject: [PATCH 22/24] Use SmallVector where possible
---
offload/liboffload/src/OffloadImpl.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/offload/liboffload/src/OffloadImpl.cpp b/offload/liboffload/src/OffloadImpl.cpp
index 1137c0845d78f7..79a4e766f2ce92 100644
--- a/offload/liboffload/src/OffloadImpl.cpp
+++ b/offload/liboffload/src/OffloadImpl.cpp
@@ -34,8 +34,9 @@ struct ol_platform_handle_t_ {
std::vector<ol_device_handle_t_> Devices;
};
-std::vector<ol_platform_handle_t_> &Platforms() {
- static std::vector<ol_platform_handle_t_> Platforms;
+using PlatformVecT = SmallVector<ol_platform_handle_t_, 4>;
+PlatformVecT &Platforms() {
+ static PlatformVecT Platforms;
return Platforms;
}
>From f82dedd0e42c487d807203efae3a3c548b72f34e Mon Sep 17 00:00:00 2001
From: Callum Fare <callum at codeplay.com>
Date: Tue, 26 Nov 2024 11:25:54 +0000
Subject: [PATCH 23/24] Fix const correctness of offload-tblgen
---
offload/tools/offload-tblgen/APIGen.cpp | 2 +-
.../tools/offload-tblgen/EntryPointGen.cpp | 2 +-
offload/tools/offload-tblgen/FuncsGen.cpp | 6 +--
offload/tools/offload-tblgen/Generators.hpp | 16 ++++---
offload/tools/offload-tblgen/PrintGen.cpp | 2 +-
offload/tools/offload-tblgen/RecordTypes.hpp | 46 +++++++++----------
.../tools/offload-tblgen/offload-tblgen.cpp | 2 +-
7 files changed, 40 insertions(+), 36 deletions(-)
diff --git a/offload/tools/offload-tblgen/APIGen.cpp b/offload/tools/offload-tblgen/APIGen.cpp
index 877b57f24a2b8a..97a2464f7a75c1 100644
--- a/offload/tools/offload-tblgen/APIGen.cpp
+++ b/offload/tools/offload-tblgen/APIGen.cpp
@@ -196,7 +196,7 @@ OL_APIEXPORT ol_result_t OL_APICALL {0}WithCodeLoc(
OS << "ol_code_location_t *CodeLocation);\n\n";
}
-void EmitOffloadAPI(RecordKeeper &Records, raw_ostream &OS) {
+void EmitOffloadAPI(const RecordKeeper &Records, raw_ostream &OS) {
OS << GenericHeader;
OS << FileHeader;
// Generate main API definitions
diff --git a/offload/tools/offload-tblgen/EntryPointGen.cpp b/offload/tools/offload-tblgen/EntryPointGen.cpp
index 6e85ebd9bfd673..990ff96a3121d9 100644
--- a/offload/tools/offload-tblgen/EntryPointGen.cpp
+++ b/offload/tools/offload-tblgen/EntryPointGen.cpp
@@ -128,7 +128,7 @@ static void EmitCodeLocWrapper(const FunctionRec &F, raw_ostream &OS) {
OS << "}\n";
}
-void EmitOffloadEntryPoints(RecordKeeper &Records, raw_ostream &OS) {
+void EmitOffloadEntryPoints(const RecordKeeper &Records, raw_ostream &OS) {
OS << GenericHeader;
for (auto *R : Records.getAllDerivedDefinitions("Function")) {
EmitValidationFunc(FunctionRec{R}, OS);
diff --git a/offload/tools/offload-tblgen/FuncsGen.cpp b/offload/tools/offload-tblgen/FuncsGen.cpp
index 17d8bc375e2bea..32386521761984 100644
--- a/offload/tools/offload-tblgen/FuncsGen.cpp
+++ b/offload/tools/offload-tblgen/FuncsGen.cpp
@@ -21,7 +21,7 @@ using namespace llvm;
using namespace offload::tblgen;
// Emit a list of just the API function names
-void EmitOffloadFuncNames(RecordKeeper &Records, raw_ostream &OS) {
+void EmitOffloadFuncNames(const RecordKeeper &Records, raw_ostream &OS) {
OS << GenericHeader;
OS << R"(
#ifndef OFFLOAD_FUNC
@@ -41,7 +41,7 @@ void EmitOffloadFuncNames(RecordKeeper &Records, raw_ostream &OS) {
OS << "\n#undef OFFLOAD_FUNC\n";
}
-void EmitOffloadExports(RecordKeeper &Records, raw_ostream &OS) {
+void EmitOffloadExports(const RecordKeeper &Records, raw_ostream &OS) {
OS << "VERS1.0 {\n";
OS << TAB_1 "global:\n";
@@ -57,7 +57,7 @@ void EmitOffloadExports(RecordKeeper &Records, raw_ostream &OS) {
}
// Emit declarations for every implementation function
-void EmitOffloadImplFuncDecls(RecordKeeper &Records, raw_ostream &OS) {
+void EmitOffloadImplFuncDecls(const RecordKeeper &Records, raw_ostream &OS) {
OS << GenericHeader;
for (auto *R : Records.getAllDerivedDefinitions("Function")) {
FunctionRec F{R};
diff --git a/offload/tools/offload-tblgen/Generators.hpp b/offload/tools/offload-tblgen/Generators.hpp
index 4e347ba2fb2946..8b6104c5cd9c61 100644
--- a/offload/tools/offload-tblgen/Generators.hpp
+++ b/offload/tools/offload-tblgen/Generators.hpp
@@ -10,10 +10,14 @@
#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,
+void EmitOffloadAPI(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
+void EmitOffloadFuncNames(const llvm::RecordKeeper &Records,
+ llvm::raw_ostream &OS);
+void EmitOffloadImplFuncDecls(const 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);
+void EmitOffloadEntryPoints(const llvm::RecordKeeper &Records,
+ llvm::raw_ostream &OS);
+void EmitOffloadPrintHeader(const llvm::RecordKeeper &Records,
+ llvm::raw_ostream &OS);
+void EmitOffloadExports(const llvm::RecordKeeper &Records,
+ llvm::raw_ostream &OS);
diff --git a/offload/tools/offload-tblgen/PrintGen.cpp b/offload/tools/offload-tblgen/PrintGen.cpp
index 518213234c80b1..2a7c63c3dfd1f7 100644
--- a/offload/tools/offload-tblgen/PrintGen.cpp
+++ b/offload/tools/offload-tblgen/PrintGen.cpp
@@ -150,7 +150,7 @@ inline std::ostream &operator<<(std::ostream &os, const struct {0} *params) {{
OS << TAB_1 "return os;\n}\n";
}
-void EmitOffloadPrintHeader(RecordKeeper &Records, raw_ostream &OS) {
+void EmitOffloadPrintHeader(const RecordKeeper &Records, raw_ostream &OS) {
OS << GenericHeader;
OS << R"""(
// Auto-generated file, do not manually edit.
diff --git a/offload/tools/offload-tblgen/RecordTypes.hpp b/offload/tools/offload-tblgen/RecordTypes.hpp
index ccd45d472cf770..0bf3256c525d9e 100644
--- a/offload/tools/offload-tblgen/RecordTypes.hpp
+++ b/offload/tools/offload-tblgen/RecordTypes.hpp
@@ -18,17 +18,17 @@ namespace tblgen {
class HandleRec {
public:
- explicit HandleRec(Record *rec) : rec(rec) {}
+ explicit HandleRec(const Record *rec) : rec(rec) {}
StringRef getName() const { return rec->getValueAsString("name"); }
StringRef getDesc() const { return rec->getValueAsString("desc"); }
private:
- Record *rec;
+ const Record *rec;
};
class MacroRec {
public:
- explicit MacroRec(Record *rec) : rec(rec) {
+ explicit MacroRec(const Record *rec) : rec(rec) {
auto Name = rec->getValueAsString("name");
auto OpenBrace = Name.find_first_of("(");
nameWithoutArgs = Name.substr(0, OpenBrace);
@@ -46,24 +46,24 @@ class MacroRec {
}
private:
- Record *rec;
+ const Record *rec;
std::string nameWithoutArgs;
};
class TypedefRec {
public:
- explicit TypedefRec(Record *rec) : rec(rec) {}
+ explicit TypedefRec(const 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;
+ const Record *rec;
};
class EnumValueRec {
public:
- explicit EnumValueRec(Record *rec) : rec(rec) {}
+ explicit EnumValueRec(const Record *rec) : rec(rec) {}
std::string getName() const { return rec->getValueAsString("name").upper(); }
StringRef getDesc() const { return rec->getValueAsString("desc"); }
StringRef getTaggedType() const {
@@ -71,13 +71,13 @@ class EnumValueRec {
}
private:
- Record *rec;
+ const Record *rec;
};
class EnumRec {
public:
- explicit EnumRec(Record *rec) : rec(rec) {
- for (auto *Val : rec->getValueAsListOfDefs("etors")) {
+ explicit EnumRec(const Record *rec) : rec(rec) {
+ for (const auto *Val : rec->getValueAsListOfDefs("etors")) {
vals.emplace_back(EnumValueRec{Val});
}
}
@@ -93,24 +93,24 @@ class EnumRec {
bool isTyped() const { return rec->getValueAsBit("is_typed"); }
private:
- Record *rec;
+ const Record *rec;
std::vector<EnumValueRec> vals;
};
class StructMemberRec {
public:
- explicit StructMemberRec(Record *rec) : rec(rec) {}
+ explicit StructMemberRec(const 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;
+ const Record *rec;
};
class StructRec {
public:
- explicit StructRec(Record *rec) : rec(rec) {
+ explicit StructRec(const Record *rec) : rec(rec) {
for (auto *Member : rec->getValueAsListOfDefs("all_members")) {
members.emplace_back(StructMemberRec(Member));
}
@@ -123,13 +123,13 @@ class StructRec {
const std::vector<StructMemberRec> &getMembers() const { return members; }
private:
- Record *rec;
+ const Record *rec;
std::vector<StructMemberRec> members;
};
class ParamRec {
public:
- explicit ParamRec(Record *rec) : rec(rec) {
+ explicit ParamRec(const Record *rec) : rec(rec) {
flags = rec->getValueAsBitsInit("flags");
auto *Range = rec->getValueAsDef("range");
auto RangeBegin = Range->getValueAsString("begin");
@@ -158,7 +158,7 @@ class ParamRec {
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; }
+ const Record *getRec() const { return rec; }
std::optional<std::pair<StringRef, StringRef>> getRange() const {
return range;
}
@@ -171,27 +171,27 @@ class ParamRec {
bool operator!=(const ParamRec &p) const { return rec != p.getRec(); }
private:
- Record *rec;
- BitsInit *flags;
+ const Record *rec;
+ const BitsInit *flags;
std::optional<std::pair<StringRef, StringRef>> range;
std::optional<std::pair<StringRef, StringRef>> typeinfo;
};
class ReturnRec {
public:
- ReturnRec(Record *rec) : rec(rec) {}
+ ReturnRec(const Record *rec) : rec(rec) {}
StringRef getValue() const { return rec->getValueAsString("value"); }
std::vector<StringRef> getConditions() const {
return rec->getValueAsListOfStrings("conditions");
}
private:
- Record *rec;
+ const Record *rec;
};
class FunctionRec {
public:
- FunctionRec(Record *rec) : rec(rec) {
+ FunctionRec(const Record *rec) : rec(rec) {
for (auto &Ret : rec->getValueAsListOfDefs("all_returns"))
rets.emplace_back(Ret);
for (auto &Param : rec->getValueAsListOfDefs("params"))
@@ -219,7 +219,7 @@ class FunctionRec {
std::vector<ReturnRec> rets;
std::vector<ParamRec> params;
- Record *rec;
+ const Record *rec;
};
} // namespace tblgen
diff --git a/offload/tools/offload-tblgen/offload-tblgen.cpp b/offload/tools/offload-tblgen/offload-tblgen.cpp
index 856ebebfc93249..1912abf5265c7c 100644
--- a/offload/tools/offload-tblgen/offload-tblgen.cpp
+++ b/offload/tools/offload-tblgen/offload-tblgen.cpp
@@ -55,7 +55,7 @@ cl::opt<ActionType> Action(
"Generate export file for the Offload library")));
}
-static bool OffloadTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
+static bool OffloadTableGenMain(raw_ostream &OS, const RecordKeeper &Records) {
switch (Action) {
case PrintRecords:
OS << Records;
>From bcb8e211add0593cf9018ddb953fc138da12a6a4 Mon Sep 17 00:00:00 2001
From: Callum Fare <callum at codeplay.com>
Date: Wed, 27 Nov 2024 13:53:27 +0000
Subject: [PATCH 24/24] Fix liboffload build with OMPT_SUPPORT enabled
---
offload/liboffload/src/OffloadImpl.cpp | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/offload/liboffload/src/OffloadImpl.cpp b/offload/liboffload/src/OffloadImpl.cpp
index 79a4e766f2ce92..457f1053f16341 100644
--- a/offload/liboffload/src/OffloadImpl.cpp
+++ b/offload/liboffload/src/OffloadImpl.cpp
@@ -40,6 +40,21 @@ PlatformVecT &Platforms() {
return Platforms;
}
+// TODO: Some plugins expect to be linked into libomptarget which defines these
+// symbols to implement ompt callbacks. The least invasive workaround here is to
+// define them in libLLVMOffload as false/null so they are never used. In future
+// it would be better to allow the plugins to implement callbacks without
+// pulling in details from libomptarget.
+#ifdef OMPT_SUPPORT
+namespace llvm::omp::target {
+namespace ompt {
+bool Initialized = false;
+ompt_get_callback_t lookupCallbackByCode = nullptr;
+ompt_function_lookup_t lookupCallbackByName = nullptr;
+} // namespace ompt
+} // namespace llvm::omp::target
+#endif
+
// 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"
More information about the llvm-commits
mailing list