diff options
| author | Callum Fare <callum@codeplay.com> | 2024-12-05 08:34:04 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-05 09:34:04 +0100 |
| commit | fd3907ccb583df99e9c19d2fe84e4e7c52d75de9 (patch) | |
| tree | deaffb6b369c1ec87261df173b32717b07f7525c /offload/liboffload/include/generated | |
| parent | 636beb6a2833ee0290935f679252c1b662721b31 (diff) | |
| download | llvm-fd3907ccb583df99e9c19d2fe84e4e7c52d75de9.zip llvm-fd3907ccb583df99e9c19d2fe84e4e7c52d75de9.tar.gz llvm-fd3907ccb583df99e9c19d2fe84e4e7c52d75de9.tar.bz2 | |
Reland #118503: [Offload] Introduce offload-tblgen and initial new API implementation (#118614)
Reland #118503. Added a fix for builds with `-DBUILD_SHARED_LIBS=ON`
(see last commit). Otherwise the changes are identical.
---
### 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.
Diffstat (limited to 'offload/liboffload/include/generated')
5 files changed, 1551 insertions, 0 deletions
diff --git a/offload/liboffload/include/generated/OffloadAPI.h b/offload/liboffload/include/generated/OffloadAPI.h new file mode 100644 index 0000000..11fcc96 --- /dev/null +++ b/offload/liboffload/include/generated/OffloadAPI.h @@ -0,0 +1,610 @@ +//===- 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 OL_VERSION_MAJOR +/// @brief Major version of the Offload API +#define OL_VERSION_MAJOR 0 +#endif // OL_VERSION_MAJOR + +/////////////////////////////////////////////////////////////////////////////// +#ifndef OL_VERSION_MINOR +/// @brief Minor version of the Offload API +#define OL_VERSION_MINOR 0 +#endif // OL_VERSION_MINOR + +/////////////////////////////////////////////////////////////////////////////// +#ifndef OL_VERSION_PATCH +/// @brief Patch version of the Offload API +#define OL_VERSION_PATCH 1 +#endif // OL_VERSION_PATCH + +/////////////////////////////////////////////////////////////////////////////// +#ifndef OL_APICALL +#if defined(_WIN32) +/// @brief Calling convention for all API functions +#define OL_APICALL __cdecl +#else +#define OL_APICALL +#endif // defined(_WIN32) +#endif // OL_APICALL + +/////////////////////////////////////////////////////////////////////////////// +#ifndef OL_APIEXPORT +#if defined(_WIN32) +/// @brief Microsoft-specific dllexport storage-class attribute +#define OL_APIEXPORT __declspec(dllexport) +#else +#define OL_APIEXPORT +#endif // defined(_WIN32) +#endif // OL_APIEXPORT + +/////////////////////////////////////////////////////////////////////////////// +#ifndef OL_DLLEXPORT +#if defined(_WIN32) +/// @brief Microsoft-specific dllexport storage-class attribute +#define OL_DLLEXPORT __declspec(dllexport) +#endif // defined(_WIN32) +#endif // OL_DLLEXPORT + +/////////////////////////////////////////////////////////////////////////////// +#ifndef OL_DLLEXPORT +#if __GNUC__ >= 4 +/// @brief GCC-specific dllexport storage-class attribute +#define OL_DLLEXPORT __attribute__((visibility("default"))) +#else +#define OL_DLLEXPORT +#endif // __GNUC__ >= 4 +#endif // OL_DLLEXPORT + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Handle of a platform instance +typedef struct ol_platform_handle_t_ *ol_platform_handle_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Handle of platform's device object +typedef struct ol_device_handle_t_ *ol_device_handle_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Handle of context object +typedef struct ol_context_handle_t_ *ol_context_handle_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Defines Return/Error codes +typedef enum ol_errc_t { + /// Success + OL_ERRC_SUCCESS = 0, + /// Invalid Value + OL_ERRC_INVALID_VALUE = 1, + /// Invalid platform + OL_ERRC_INVALID_PLATFORM = 2, + /// Device not found + OL_ERRC_DEVICE_NOT_FOUND = 3, + /// Invalid device + OL_ERRC_INVALID_DEVICE = 4, + /// Device hung, reset, was removed, or driver update occurred + OL_ERRC_DEVICE_LOST = 5, + /// plugin is not initialized or specific entry-point is not implemented + OL_ERRC_UNINITIALIZED = 6, + /// Out of resources + OL_ERRC_OUT_OF_RESOURCES = 7, + /// generic error code for unsupported versions + OL_ERRC_UNSUPPORTED_VERSION = 8, + /// generic error code for unsupported features + OL_ERRC_UNSUPPORTED_FEATURE = 9, + /// generic error code for invalid arguments + OL_ERRC_INVALID_ARGUMENT = 10, + /// handle argument is not valid + OL_ERRC_INVALID_NULL_HANDLE = 11, + /// pointer argument may not be nullptr + OL_ERRC_INVALID_NULL_POINTER = 12, + /// invalid size or dimensions (e.g., must not be zero, or is out of bounds) + OL_ERRC_INVALID_SIZE = 13, + /// enumerator argument is not valid + OL_ERRC_INVALID_ENUMERATION = 14, + /// enumerator argument is not supported by the device + OL_ERRC_UNSUPPORTED_ENUMERATION = 15, + /// Unknown or internal error + OL_ERRC_UNKNOWN = 16, + /// @cond + OL_ERRC_FORCE_UINT32 = 0x7fffffff + /// @endcond + +} ol_errc_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Details of the error condition returned by an API call +typedef struct ol_error_struct_t { + ol_errc_t Code; /// The error code + const char *Details; /// String containing error details +} ol_error_struct_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Result type returned by all entry points. +typedef const ol_error_struct_t *ol_result_t; + +/////////////////////////////////////////////////////////////////////////////// +#ifndef OL_SUCCESS +/// @brief Success condition +#define OL_SUCCESS NULL +#endif // OL_SUCCESS + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Code location information that can optionally be associated with an +/// API call +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 +} ol_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 `olShutDown` +/// +/// @returns +/// - ::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 +/// +/// @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 +/// - ::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 +/// +/// @details +/// - Multiple calls to this function will return identical platforms +/// handles, in the same order. +/// +/// @returns +/// - ::OL_RESULT_SUCCESS +/// - ::OL_ERRC_UNINITIALIZED +/// - ::OL_ERRC_DEVICE_LOST +/// - ::OL_ERRC_INVALID_SIZE +/// + `NumEntries == 0` +/// - ::OL_ERRC_INVALID_NULL_HANDLE +/// - ::OL_ERRC_INVALID_NULL_POINTER +/// + `NULL == Platforms` +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 olGetPlatform shall only retrieve that + // number of platforms. + ol_platform_handle_t *Platforms); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Retrieves the number of available platforms +/// +/// @details +/// +/// @returns +/// - ::OL_RESULT_SUCCESS +/// - ::OL_ERRC_UNINITIALIZED +/// - ::OL_ERRC_DEVICE_LOST +/// - ::OL_ERRC_INVALID_NULL_HANDLE +/// - ::OL_ERRC_INVALID_NULL_POINTER +/// + `NULL == NumPlatforms` +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 ol_platform_info_t { + /// [char[]] The string denoting name of the platform. The size of the info + /// needs to be dynamically queried. + 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. + 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. + OL_PLATFORM_INFO_VERSION = 2, + /// [ol_platform_backend_t] The native backend of the platform. + OL_PLATFORM_INFO_BACKEND = 3, + /// @cond + OL_PLATFORM_INFO_FORCE_UINT32 = 0x7fffffff + /// @endcond + +} ol_platform_info_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Identifies the native backend of the platform +typedef enum ol_platform_backend_t { + /// The backend is not recognized + OL_PLATFORM_BACKEND_UNKNOWN = 0, + /// The backend is CUDA + OL_PLATFORM_BACKEND_CUDA = 1, + /// The backend is AMDGPU + OL_PLATFORM_BACKEND_AMDGPU = 2, + /// @cond + OL_PLATFORM_BACKEND_FORCE_UINT32 = 0x7fffffff + /// @endcond + +} ol_platform_backend_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Queries the given property of the platform +/// +/// @details +/// - `olGetPlatformInfoSize` can be used to query the storage size required +/// for the given query. +/// +/// @returns +/// - ::OL_RESULT_SUCCESS +/// - ::OL_ERRC_UNINITIALIZED +/// - ::OL_ERRC_DEVICE_LOST +/// - ::OL_ERRC_UNSUPPORTED_ENUMERATION +/// + If `PropName` is not supported by the platform. +/// - ::OL_ERRC_INVALID_SIZE +/// + `PropSize == 0` +/// + If `PropSize` is less than the real number of bytes needed to +/// return the info. +/// - ::OL_ERRC_INVALID_PLATFORM +/// - ::OL_ERRC_INVALID_NULL_HANDLE +/// + `NULL == Platform` +/// - ::OL_ERRC_INVALID_NULL_POINTER +/// + `NULL == PropValue` +OL_APIEXPORT ol_result_t OL_APICALL olGetPlatformInfo( + // [in] handle of the platform + ol_platform_handle_t Platform, + // [in] type of the info to retrieve + 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 + // OL_ERRC_INVALID_SIZE error is returned and pPlatformInfo is not used. + void *PropValue); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Returns the storage size of the given platform query +/// +/// @details +/// +/// @returns +/// - ::OL_RESULT_SUCCESS +/// - ::OL_ERRC_UNINITIALIZED +/// - ::OL_ERRC_DEVICE_LOST +/// - ::OL_ERRC_UNSUPPORTED_ENUMERATION +/// + If `PropName` is not supported by the platform. +/// - ::OL_ERRC_INVALID_PLATFORM +/// - ::OL_ERRC_INVALID_NULL_HANDLE +/// + `NULL == Platform` +/// - ::OL_ERRC_INVALID_NULL_POINTER +/// + `NULL == PropSizeRet` +OL_APIEXPORT ol_result_t OL_APICALL olGetPlatformInfoSize( + // [in] handle of the platform + ol_platform_handle_t Platform, + // [in] type of the info to query + 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 ol_device_type_t { + /// The default device type as preferred by the runtime + OL_DEVICE_TYPE_DEFAULT = 0, + /// Devices of all types + OL_DEVICE_TYPE_ALL = 1, + /// GPU device type + OL_DEVICE_TYPE_GPU = 2, + /// CPU device type + OL_DEVICE_TYPE_CPU = 3, + /// @cond + OL_DEVICE_TYPE_FORCE_UINT32 = 0x7fffffff + /// @endcond + +} ol_device_type_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Supported device info +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 + OL_DEVICE_INFO_NAME = 2, + /// [char[]] Device vendor + OL_DEVICE_INFO_VENDOR = 3, + /// [char[]] Driver version + OL_DEVICE_INFO_DRIVER_VERSION = 4, + /// @cond + OL_DEVICE_INFO_FORCE_UINT32 = 0x7fffffff + /// @endcond + +} ol_device_info_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Retrieves the number of available devices within a platform +/// +/// @details +/// +/// @returns +/// - ::OL_RESULT_SUCCESS +/// - ::OL_ERRC_UNINITIALIZED +/// - ::OL_ERRC_DEVICE_LOST +/// - ::OL_ERRC_INVALID_NULL_HANDLE +/// + `NULL == Platform` +/// - ::OL_ERRC_INVALID_NULL_POINTER +/// + `NULL == NumDevices` +OL_APIEXPORT ol_result_t OL_APICALL olGetDeviceCount( + // [in] handle of the platform instance + ol_platform_handle_t Platform, + // [out] pointer to the number of devices. + uint32_t *NumDevices); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Retrieves devices within a platform +/// +/// @details +/// - Multiple calls to this function will return identical device handles, +/// in the same order. +/// +/// @returns +/// - ::OL_RESULT_SUCCESS +/// - ::OL_ERRC_UNINITIALIZED +/// - ::OL_ERRC_DEVICE_LOST +/// - ::OL_ERRC_INVALID_SIZE +/// + `NumEntries == 0` +/// - ::OL_ERRC_INVALID_NULL_HANDLE +/// + `NULL == Platform` +/// - ::OL_ERRC_INVALID_NULL_POINTER +/// + `NULL == Devices` +OL_APIEXPORT ol_result_t OL_APICALL olGetDevice( + // [in] handle of the platform instance + 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. + ol_device_handle_t *Devices); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Queries the given property of the device +/// +/// @details +/// +/// @returns +/// - ::OL_RESULT_SUCCESS +/// - ::OL_ERRC_UNINITIALIZED +/// - ::OL_ERRC_DEVICE_LOST +/// - ::OL_ERRC_UNSUPPORTED_ENUMERATION +/// + If `PropName` is not supported by the device. +/// - ::OL_ERRC_INVALID_SIZE +/// + `PropSize == 0` +/// + If `PropSize` is less than the real number of bytes needed to +/// return the info. +/// - ::OL_ERRC_INVALID_DEVICE +/// - ::OL_ERRC_INVALID_NULL_HANDLE +/// + `NULL == Device` +/// - ::OL_ERRC_INVALID_NULL_POINTER +/// + `NULL == PropValue` +OL_APIEXPORT ol_result_t OL_APICALL olGetDeviceInfo( + // [in] handle of the device instance + ol_device_handle_t Device, + // [in] type of the info to retrieve + 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 + // OL_ERRC_INVALID_SIZE error is returned and PropValue is not used. + void *PropValue); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Returns the storage size of the given device query +/// +/// @details +/// +/// @returns +/// - ::OL_RESULT_SUCCESS +/// - ::OL_ERRC_UNINITIALIZED +/// - ::OL_ERRC_DEVICE_LOST +/// - ::OL_ERRC_UNSUPPORTED_ENUMERATION +/// + If `PropName` is not supported by the device. +/// - ::OL_ERRC_INVALID_DEVICE +/// - ::OL_ERRC_INVALID_NULL_HANDLE +/// + `NULL == Device` +/// - ::OL_ERRC_INVALID_NULL_POINTER +/// + `NULL == PropSizeRet` +OL_APIEXPORT ol_result_t OL_APICALL olGetDeviceInfoSize( + // [in] handle of the device instance + ol_device_handle_t Device, + // [in] type of the info to retrieve + ol_device_info_t PropName, + // [out] pointer to the number of bytes required to store the query + size_t *PropSizeRet); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function parameters for olGetPlatform +/// @details Each entry is a pointer to the parameter passed to the function; +typedef struct ol_get_platform_params_t { + uint32_t *pNumEntries; + ol_platform_handle_t **pPlatforms; +} ol_get_platform_params_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function parameters for olGetPlatformCount +/// @details Each entry is a pointer to the parameter passed to the function; +typedef struct ol_get_platform_count_params_t { + uint32_t **pNumPlatforms; +} ol_get_platform_count_params_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function parameters for olGetPlatformInfo +/// @details Each entry is a pointer to the parameter passed to the function; +typedef struct ol_get_platform_info_params_t { + ol_platform_handle_t *pPlatform; + ol_platform_info_t *pPropName; + size_t *pPropSize; + void **pPropValue; +} ol_get_platform_info_params_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function parameters for olGetPlatformInfoSize +/// @details Each entry is a pointer to the parameter passed to the function; +typedef struct ol_get_platform_info_size_params_t { + ol_platform_handle_t *pPlatform; + ol_platform_info_t *pPropName; + size_t **pPropSizeRet; +} ol_get_platform_info_size_params_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function parameters for olGetDeviceCount +/// @details Each entry is a pointer to the parameter passed to the function; +typedef struct ol_get_device_count_params_t { + ol_platform_handle_t *pPlatform; + uint32_t **pNumDevices; +} ol_get_device_count_params_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function parameters for olGetDevice +/// @details Each entry is a pointer to the parameter passed to the function; +typedef struct ol_get_device_params_t { + ol_platform_handle_t *pPlatform; + uint32_t *pNumEntries; + ol_device_handle_t **pDevices; +} ol_get_device_params_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function parameters for olGetDeviceInfo +/// @details Each entry is a pointer to the parameter passed to the function; +typedef struct ol_get_device_info_params_t { + ol_device_handle_t *pDevice; + ol_device_info_t *pPropName; + size_t *pPropSize; + void **pPropValue; +} ol_get_device_info_params_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function parameters for olGetDeviceInfoSize +/// @details Each entry is a pointer to the parameter passed to the function; +typedef struct ol_get_device_info_size_params_t { + ol_device_handle_t *pDevice; + ol_device_info_t *pPropName; + size_t **pPropSizeRet; +} ol_get_device_info_size_params_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @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 olGetPlatform that also sets source code location +/// information +/// @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 olGetPlatformCount that also sets source code location +/// information +/// @details See also ::olGetPlatformCount +OL_APIEXPORT ol_result_t OL_APICALL olGetPlatformCountWithCodeLoc( + uint32_t *NumPlatforms, ol_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 olGetPlatformInfoSize that also sets source code location +/// information +/// @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 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 olGetDevice that also sets source code location +/// information +/// @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 olGetDeviceInfo that also sets source code location +/// information +/// @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 olGetDeviceInfoSize that also sets source code location +/// information +/// @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" +#endif diff --git a/offload/liboffload/include/generated/OffloadEntryPoints.inc b/offload/liboffload/include/generated/OffloadEntryPoints.inc new file mode 100644 index 0000000..49c1c816 --- /dev/null +++ b/offload/liboffload/include/generated/OffloadEntryPoints.inc @@ -0,0 +1,441 @@ +//===- 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 +// +//===----------------------------------------------------------------------===// + +/////////////////////////////////////////////////////////////////////////////// +ol_impl_result_t olInit_val() { + if (true /*enableParameterValidation*/) { + } + + return olInit_impl(); +} +OL_APIEXPORT ol_result_t OL_APICALL olInit() { + if (offloadConfig().TracingEnabled) { + std::cout << "---> olInit"; + } + + ol_result_t Result = olInit_val(); + + if (offloadConfig().TracingEnabled) { + std::cout << "()"; + std::cout << "-> " << Result << "\n"; + if (Result && Result->Details) { + std::cout << " *Error Details* " << Result->Details << " \n"; + } + } + return Result; +} +ol_result_t olInitWithCodeLoc(ol_code_location_t *CodeLocation) { + currentCodeLocation() = CodeLocation; + ol_result_t Result = olInit(); + + currentCodeLocation() = nullptr; + return Result; +} + +/////////////////////////////////////////////////////////////////////////////// +ol_impl_result_t olShutDown_val() { + if (true /*enableParameterValidation*/) { + } + + return olShutDown_impl(); +} +OL_APIEXPORT ol_result_t OL_APICALL olShutDown() { + if (offloadConfig().TracingEnabled) { + std::cout << "---> olShutDown"; + } + + ol_result_t Result = olShutDown_val(); + + if (offloadConfig().TracingEnabled) { + std::cout << "()"; + std::cout << "-> " << Result << "\n"; + if (Result && Result->Details) { + std::cout << " *Error Details* " << Result->Details << " \n"; + } + } + return Result; +} +ol_result_t olShutDownWithCodeLoc(ol_code_location_t *CodeLocation) { + currentCodeLocation() = CodeLocation; + ol_result_t Result = olShutDown(); + + currentCodeLocation() = nullptr; + return Result; +} + +/////////////////////////////////////////////////////////////////////////////// +ol_impl_result_t olGetPlatform_val(uint32_t NumEntries, + ol_platform_handle_t *Platforms) { + if (true /*enableParameterValidation*/) { + if (NumEntries == 0) { + return OL_ERRC_INVALID_SIZE; + } + + if (NULL == Platforms) { + return OL_ERRC_INVALID_NULL_POINTER; + } + } + + return olGetPlatform_impl(NumEntries, Platforms); +} +OL_APIEXPORT ol_result_t OL_APICALL +olGetPlatform(uint32_t NumEntries, ol_platform_handle_t *Platforms) { + if (offloadConfig().TracingEnabled) { + std::cout << "---> olGetPlatform"; + } + + ol_result_t Result = olGetPlatform_val(NumEntries, Platforms); + + if (offloadConfig().TracingEnabled) { + ol_get_platform_params_t Params = {&NumEntries, &Platforms}; + std::cout << "(" << &Params << ")"; + std::cout << "-> " << Result << "\n"; + if (Result && Result->Details) { + std::cout << " *Error Details* " << Result->Details << " \n"; + } + } + return Result; +} +ol_result_t olGetPlatformWithCodeLoc(uint32_t NumEntries, + ol_platform_handle_t *Platforms, + ol_code_location_t *CodeLocation) { + currentCodeLocation() = CodeLocation; + ol_result_t Result = olGetPlatform(NumEntries, Platforms); + + currentCodeLocation() = nullptr; + return Result; +} + +/////////////////////////////////////////////////////////////////////////////// +ol_impl_result_t olGetPlatformCount_val(uint32_t *NumPlatforms) { + if (true /*enableParameterValidation*/) { + if (NULL == NumPlatforms) { + return OL_ERRC_INVALID_NULL_POINTER; + } + } + + return olGetPlatformCount_impl(NumPlatforms); +} +OL_APIEXPORT ol_result_t OL_APICALL olGetPlatformCount(uint32_t *NumPlatforms) { + if (offloadConfig().TracingEnabled) { + std::cout << "---> olGetPlatformCount"; + } + + ol_result_t Result = olGetPlatformCount_val(NumPlatforms); + + if (offloadConfig().TracingEnabled) { + ol_get_platform_count_params_t Params = {&NumPlatforms}; + std::cout << "(" << &Params << ")"; + std::cout << "-> " << Result << "\n"; + if (Result && Result->Details) { + std::cout << " *Error Details* " << Result->Details << " \n"; + } + } + return Result; +} +ol_result_t olGetPlatformCountWithCodeLoc(uint32_t *NumPlatforms, + ol_code_location_t *CodeLocation) { + currentCodeLocation() = CodeLocation; + ol_result_t Result = olGetPlatformCount(NumPlatforms); + + currentCodeLocation() = nullptr; + return Result; +} + +/////////////////////////////////////////////////////////////////////////////// +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 OL_ERRC_INVALID_SIZE; + } + + if (NULL == Platform) { + return OL_ERRC_INVALID_NULL_HANDLE; + } + + if (NULL == PropValue) { + return OL_ERRC_INVALID_NULL_POINTER; + } + } + + return olGetPlatformInfo_impl(Platform, PropName, PropSize, 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 << "---> olGetPlatformInfo"; + } + + ol_result_t Result = + olGetPlatformInfo_val(Platform, PropName, PropSize, PropValue); + + if (offloadConfig().TracingEnabled) { + ol_get_platform_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"; + } + } + return Result; +} +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; + ol_result_t Result = + olGetPlatformInfo(Platform, PropName, PropSize, PropValue); + + currentCodeLocation() = nullptr; + return Result; +} + +/////////////////////////////////////////////////////////////////////////////// +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 OL_ERRC_INVALID_NULL_HANDLE; + } + + if (NULL == PropSizeRet) { + return OL_ERRC_INVALID_NULL_POINTER; + } + } + + return olGetPlatformInfoSize_impl(Platform, PropName, 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 << "---> olGetPlatformInfoSize"; + } + + ol_result_t Result = + olGetPlatformInfoSize_val(Platform, PropName, PropSizeRet); + + if (offloadConfig().TracingEnabled) { + ol_get_platform_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"; + } + } + return Result; +} +ol_result_t olGetPlatformInfoSizeWithCodeLoc(ol_platform_handle_t Platform, + ol_platform_info_t PropName, + size_t *PropSizeRet, + ol_code_location_t *CodeLocation) { + currentCodeLocation() = CodeLocation; + ol_result_t Result = olGetPlatformInfoSize(Platform, PropName, PropSizeRet); + + currentCodeLocation() = nullptr; + return Result; +} + +/////////////////////////////////////////////////////////////////////////////// +ol_impl_result_t olGetDeviceCount_val(ol_platform_handle_t Platform, + uint32_t *NumDevices) { + if (true /*enableParameterValidation*/) { + if (NULL == Platform) { + return OL_ERRC_INVALID_NULL_HANDLE; + } + + if (NULL == NumDevices) { + return OL_ERRC_INVALID_NULL_POINTER; + } + } + + return olGetDeviceCount_impl(Platform, NumDevices); +} +OL_APIEXPORT ol_result_t OL_APICALL +olGetDeviceCount(ol_platform_handle_t Platform, uint32_t *NumDevices) { + if (offloadConfig().TracingEnabled) { + std::cout << "---> olGetDeviceCount"; + } + + ol_result_t Result = olGetDeviceCount_val(Platform, NumDevices); + + if (offloadConfig().TracingEnabled) { + ol_get_device_count_params_t Params = {&Platform, &NumDevices}; + std::cout << "(" << &Params << ")"; + std::cout << "-> " << Result << "\n"; + if (Result && Result->Details) { + std::cout << " *Error Details* " << Result->Details << " \n"; + } + } + return Result; +} +ol_result_t olGetDeviceCountWithCodeLoc(ol_platform_handle_t Platform, + uint32_t *NumDevices, + ol_code_location_t *CodeLocation) { + currentCodeLocation() = CodeLocation; + ol_result_t Result = olGetDeviceCount(Platform, NumDevices); + + currentCodeLocation() = nullptr; + return Result; +} + +/////////////////////////////////////////////////////////////////////////////// +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 OL_ERRC_INVALID_SIZE; + } + + if (NULL == Platform) { + return OL_ERRC_INVALID_NULL_HANDLE; + } + + if (NULL == Devices) { + return OL_ERRC_INVALID_NULL_POINTER; + } + } + + return olGetDevice_impl(Platform, NumEntries, 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 << "---> olGetDevice"; + } + + ol_result_t Result = olGetDevice_val(Platform, NumEntries, Devices); + + if (offloadConfig().TracingEnabled) { + ol_get_device_params_t Params = {&Platform, &NumEntries, &Devices}; + std::cout << "(" << &Params << ")"; + std::cout << "-> " << Result << "\n"; + if (Result && Result->Details) { + std::cout << " *Error Details* " << Result->Details << " \n"; + } + } + return Result; +} +ol_result_t olGetDeviceWithCodeLoc(ol_platform_handle_t Platform, + uint32_t NumEntries, + ol_device_handle_t *Devices, + ol_code_location_t *CodeLocation) { + currentCodeLocation() = CodeLocation; + ol_result_t Result = olGetDevice(Platform, NumEntries, Devices); + + currentCodeLocation() = nullptr; + return Result; +} + +/////////////////////////////////////////////////////////////////////////////// +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 OL_ERRC_INVALID_SIZE; + } + + if (NULL == Device) { + return OL_ERRC_INVALID_NULL_HANDLE; + } + + if (NULL == PropValue) { + return OL_ERRC_INVALID_NULL_POINTER; + } + } + + return olGetDeviceInfo_impl(Device, PropName, PropSize, 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 << "---> olGetDeviceInfo"; + } + + ol_result_t Result = + olGetDeviceInfo_val(Device, PropName, PropSize, PropValue); + + if (offloadConfig().TracingEnabled) { + ol_get_device_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"; + } + } + return Result; +} +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; + ol_result_t Result = olGetDeviceInfo(Device, PropName, PropSize, PropValue); + + currentCodeLocation() = nullptr; + return Result; +} + +/////////////////////////////////////////////////////////////////////////////// +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 OL_ERRC_INVALID_NULL_HANDLE; + } + + if (NULL == PropSizeRet) { + return OL_ERRC_INVALID_NULL_POINTER; + } + } + + return olGetDeviceInfoSize_impl(Device, PropName, 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 << "---> olGetDeviceInfoSize"; + } + + ol_result_t Result = olGetDeviceInfoSize_val(Device, PropName, PropSizeRet); + + if (offloadConfig().TracingEnabled) { + ol_get_device_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"; + } + } + return Result; +} +ol_result_t olGetDeviceInfoSizeWithCodeLoc(ol_device_handle_t Device, + ol_device_info_t PropName, + size_t *PropSizeRet, + ol_code_location_t *CodeLocation) { + currentCodeLocation() = CodeLocation; + ol_result_t Result = olGetDeviceInfoSize(Device, PropName, PropSizeRet); + + currentCodeLocation() = nullptr; + return Result; +} diff --git a/offload/liboffload/include/generated/OffloadFuncs.inc b/offload/liboffload/include/generated/OffloadFuncs.inc new file mode 100644 index 0000000..4811549 --- /dev/null +++ b/offload/liboffload/include/generated/OffloadFuncs.inc @@ -0,0 +1,34 @@ +//===- 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(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/liboffload/include/generated/OffloadImplFuncDecls.inc b/offload/liboffload/include/generated/OffloadImplFuncDecls.inc new file mode 100644 index 0000000..5b26b26 --- /dev/null +++ b/offload/liboffload/include/generated/OffloadImplFuncDecls.inc @@ -0,0 +1,38 @@ +//===- 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 +// +//===----------------------------------------------------------------------===// +ol_impl_result_t olInit_impl(); + +ol_impl_result_t olShutDown_impl(); + +ol_impl_result_t olGetPlatform_impl(uint32_t NumEntries, + ol_platform_handle_t *Platforms); + +ol_impl_result_t olGetPlatformCount_impl(uint32_t *NumPlatforms); + +ol_impl_result_t olGetPlatformInfo_impl(ol_platform_handle_t Platform, + ol_platform_info_t PropName, + size_t PropSize, void *PropValue); + +ol_impl_result_t olGetPlatformInfoSize_impl(ol_platform_handle_t Platform, + ol_platform_info_t PropName, + size_t *PropSizeRet); + +ol_impl_result_t olGetDeviceCount_impl(ol_platform_handle_t Platform, + uint32_t *NumDevices); + +ol_impl_result_t olGetDevice_impl(ol_platform_handle_t Platform, + uint32_t NumEntries, + ol_device_handle_t *Devices); + +ol_impl_result_t olGetDeviceInfo_impl(ol_device_handle_t Device, + ol_device_info_t PropName, + size_t PropSize, void *PropValue); + +ol_impl_result_t olGetDeviceInfoSize_impl(ol_device_handle_t Device, + ol_device_info_t PropName, + size_t *PropSizeRet); diff --git a/offload/liboffload/include/generated/OffloadPrint.hpp b/offload/liboffload/include/generated/OffloadPrint.hpp new file mode 100644 index 0000000..8981bb0 --- /dev/null +++ b/offload/liboffload/include/generated/OffloadPrint.hpp @@ -0,0 +1,428 @@ +//===- 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 <OffloadAPI.h> +#include <ostream> + +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); +template <typename T> struct is_handle : std::false_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 ol_errc_t value); +inline std::ostream &operator<<(std::ostream &os, + enum ol_platform_info_t value); +inline std::ostream &operator<<(std::ostream &os, + 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 ol_errc_t type +/// @returns std::ostream & +inline std::ostream &operator<<(std::ostream &os, enum ol_errc_t value) { + switch (value) { + case OL_ERRC_SUCCESS: + os << "OL_ERRC_SUCCESS"; + break; + case OL_ERRC_INVALID_VALUE: + os << "OL_ERRC_INVALID_VALUE"; + break; + case OL_ERRC_INVALID_PLATFORM: + os << "OL_ERRC_INVALID_PLATFORM"; + break; + case OL_ERRC_DEVICE_NOT_FOUND: + os << "OL_ERRC_DEVICE_NOT_FOUND"; + break; + case OL_ERRC_INVALID_DEVICE: + os << "OL_ERRC_INVALID_DEVICE"; + break; + case OL_ERRC_DEVICE_LOST: + os << "OL_ERRC_DEVICE_LOST"; + break; + case OL_ERRC_UNINITIALIZED: + os << "OL_ERRC_UNINITIALIZED"; + break; + case OL_ERRC_OUT_OF_RESOURCES: + os << "OL_ERRC_OUT_OF_RESOURCES"; + break; + case OL_ERRC_UNSUPPORTED_VERSION: + os << "OL_ERRC_UNSUPPORTED_VERSION"; + break; + case OL_ERRC_UNSUPPORTED_FEATURE: + os << "OL_ERRC_UNSUPPORTED_FEATURE"; + break; + case OL_ERRC_INVALID_ARGUMENT: + os << "OL_ERRC_INVALID_ARGUMENT"; + break; + case OL_ERRC_INVALID_NULL_HANDLE: + os << "OL_ERRC_INVALID_NULL_HANDLE"; + break; + case OL_ERRC_INVALID_NULL_POINTER: + os << "OL_ERRC_INVALID_NULL_POINTER"; + break; + case OL_ERRC_INVALID_SIZE: + os << "OL_ERRC_INVALID_SIZE"; + break; + case OL_ERRC_INVALID_ENUMERATION: + os << "OL_ERRC_INVALID_ENUMERATION"; + break; + case OL_ERRC_UNSUPPORTED_ENUMERATION: + os << "OL_ERRC_UNSUPPORTED_ENUMERATION"; + break; + case OL_ERRC_UNKNOWN: + os << "OL_ERRC_UNKNOWN"; + break; + default: + os << "unknown enumerator"; + break; + } + return os; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Print operator for the ol_platform_info_t type +/// @returns std::ostream & +inline std::ostream &operator<<(std::ostream &os, + enum ol_platform_info_t value) { + switch (value) { + case OL_PLATFORM_INFO_NAME: + os << "OL_PLATFORM_INFO_NAME"; + break; + case OL_PLATFORM_INFO_VENDOR_NAME: + os << "OL_PLATFORM_INFO_VENDOR_NAME"; + break; + case OL_PLATFORM_INFO_VERSION: + os << "OL_PLATFORM_INFO_VERSION"; + break; + case OL_PLATFORM_INFO_BACKEND: + os << "OL_PLATFORM_INFO_BACKEND"; + break; + default: + os << "unknown enumerator"; + break; + } + return os; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Print type-tagged ol_platform_info_t enum value +/// @returns std::ostream & +template <> +inline void printTagged(std::ostream &os, const void *ptr, + ol_platform_info_t value, size_t size) { + if (ptr == NULL) { + printPtr(os, ptr); + return; + } + + switch (value) { + case OL_PLATFORM_INFO_NAME: { + printPtr(os, (const char *)ptr); + break; + } + case OL_PLATFORM_INFO_VENDOR_NAME: { + printPtr(os, (const char *)ptr); + break; + } + case OL_PLATFORM_INFO_VERSION: { + printPtr(os, (const char *)ptr); + break; + } + 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 << ")"; + break; + } + default: + os << "unknown enumerator"; + break; + } +} +/////////////////////////////////////////////////////////////////////////////// +/// @brief Print operator for the ol_platform_backend_t type +/// @returns std::ostream & +inline std::ostream &operator<<(std::ostream &os, + enum ol_platform_backend_t value) { + switch (value) { + case OL_PLATFORM_BACKEND_UNKNOWN: + os << "OL_PLATFORM_BACKEND_UNKNOWN"; + break; + case OL_PLATFORM_BACKEND_CUDA: + os << "OL_PLATFORM_BACKEND_CUDA"; + break; + case OL_PLATFORM_BACKEND_AMDGPU: + os << "OL_PLATFORM_BACKEND_AMDGPU"; + break; + default: + os << "unknown enumerator"; + break; + } + return os; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Print operator for the ol_device_type_t type +/// @returns std::ostream & +inline std::ostream &operator<<(std::ostream &os, enum ol_device_type_t value) { + switch (value) { + case OL_DEVICE_TYPE_DEFAULT: + os << "OL_DEVICE_TYPE_DEFAULT"; + break; + case OL_DEVICE_TYPE_ALL: + os << "OL_DEVICE_TYPE_ALL"; + break; + case OL_DEVICE_TYPE_GPU: + os << "OL_DEVICE_TYPE_GPU"; + break; + case OL_DEVICE_TYPE_CPU: + os << "OL_DEVICE_TYPE_CPU"; + break; + default: + os << "unknown enumerator"; + break; + } + return os; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Print operator for the ol_device_info_t type +/// @returns std::ostream & +inline std::ostream &operator<<(std::ostream &os, enum ol_device_info_t value) { + switch (value) { + case OL_DEVICE_INFO_TYPE: + os << "OL_DEVICE_INFO_TYPE"; + break; + case OL_DEVICE_INFO_PLATFORM: + os << "OL_DEVICE_INFO_PLATFORM"; + break; + case OL_DEVICE_INFO_NAME: + os << "OL_DEVICE_INFO_NAME"; + break; + case OL_DEVICE_INFO_VENDOR: + os << "OL_DEVICE_INFO_VENDOR"; + break; + case OL_DEVICE_INFO_DRIVER_VERSION: + os << "OL_DEVICE_INFO_DRIVER_VERSION"; + break; + default: + os << "unknown enumerator"; + break; + } + return os; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Print type-tagged ol_device_info_t enum value +/// @returns std::ostream & +template <> +inline void printTagged(std::ostream &os, const void *ptr, + ol_device_info_t value, size_t size) { + if (ptr == NULL) { + printPtr(os, ptr); + return; + } + + switch (value) { + 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 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 OL_DEVICE_INFO_NAME: { + printPtr(os, (const char *)ptr); + break; + } + case OL_DEVICE_INFO_VENDOR: { + printPtr(os, (const char *)ptr); + break; + } + case OL_DEVICE_INFO_DRIVER_VERSION: { + printPtr(os, (const char *)ptr); + break; + } + default: + os << "unknown enumerator"; + break; + } +} + +inline std::ostream &operator<<(std::ostream &os, + const ol_error_struct_t *Err) { + if (Err == nullptr) { + os << "OL_SUCCESS"; + } else { + os << Err->Code; + } + return os; +} + +inline std::ostream &operator<<(std::ostream &os, + const struct ol_get_platform_params_t *params) { + os << ".NumEntries = "; + os << *params->pNumEntries; + os << ", "; + os << ".Platforms = "; + os << "{"; + for (size_t i = 0; i < *params->pNumEntries; i++) { + if (i > 0) { + os << ", "; + } + printPtr(os, (*params->pPlatforms)[i]); + } + os << "}"; + return os; +} + +inline std::ostream & +operator<<(std::ostream &os, + const struct ol_get_platform_count_params_t *params) { + os << ".NumPlatforms = "; + printPtr(os, *params->pNumPlatforms); + return os; +} + +inline std::ostream & +operator<<(std::ostream &os, + const struct ol_get_platform_info_params_t *params) { + os << ".Platform = "; + printPtr(os, *params->pPlatform); + os << ", "; + os << ".PropName = "; + os << *params->pPropName; + os << ", "; + os << ".PropSize = "; + os << *params->pPropSize; + os << ", "; + os << ".PropValue = "; + printTagged(os, *params->pPropValue, *params->pPropName, *params->pPropSize); + return os; +} + +inline std::ostream & +operator<<(std::ostream &os, + const struct ol_get_platform_info_size_params_t *params) { + os << ".Platform = "; + printPtr(os, *params->pPlatform); + os << ", "; + os << ".PropName = "; + os << *params->pPropName; + os << ", "; + os << ".PropSizeRet = "; + printPtr(os, *params->pPropSizeRet); + return os; +} + +inline std::ostream & +operator<<(std::ostream &os, + const struct ol_get_device_count_params_t *params) { + os << ".Platform = "; + printPtr(os, *params->pPlatform); + os << ", "; + os << ".NumDevices = "; + printPtr(os, *params->pNumDevices); + return os; +} + +inline std::ostream &operator<<(std::ostream &os, + const struct ol_get_device_params_t *params) { + os << ".Platform = "; + printPtr(os, *params->pPlatform); + os << ", "; + os << ".NumEntries = "; + os << *params->pNumEntries; + os << ", "; + os << ".Devices = "; + os << "{"; + for (size_t i = 0; i < *params->pNumEntries; i++) { + if (i > 0) { + os << ", "; + } + printPtr(os, (*params->pDevices)[i]); + } + os << "}"; + return os; +} + +inline std::ostream & +operator<<(std::ostream &os, const struct ol_get_device_info_params_t *params) { + os << ".Device = "; + printPtr(os, *params->pDevice); + os << ", "; + os << ".PropName = "; + os << *params->pPropName; + os << ", "; + os << ".PropSize = "; + os << *params->pPropSize; + os << ", "; + os << ".PropValue = "; + printTagged(os, *params->pPropValue, *params->pPropName, *params->pPropSize); + return os; +} + +inline std::ostream & +operator<<(std::ostream &os, + const struct ol_get_device_info_size_params_t *params) { + os << ".Device = "; + printPtr(os, *params->pDevice); + os << ", "; + os << ".PropName = "; + os << *params->pPropName; + os << ", "; + os << ".PropSizeRet = "; + printPtr(os, *params->pPropSizeRet); + return os; +} + +/////////////////////////////////////////////////////////////////////////////// +// @brief Print pointer value +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>) { + 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 OL_SUCCESS; +} |
