File indexing completed on 2026-05-10 08:45:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #pragma once
0012
0013 #include <OffloadAPI.h>
0014 #include <ostream>
0015
0016 template <typename T>
0017 inline ol_result_t printPtr(std::ostream &os, const T *ptr);
0018 template <typename T>
0019 inline void printTagged(std::ostream &os, const void *ptr, T value,
0020 size_t size);
0021 template <typename T> struct is_handle : std::false_type {};
0022 template <> struct is_handle<ol_platform_handle_t> : std::true_type {};
0023 template <> struct is_handle<ol_device_handle_t> : std::true_type {};
0024 template <> struct is_handle<ol_context_handle_t> : std::true_type {};
0025 template <typename T> inline constexpr bool is_handle_v = is_handle<T>::value;
0026
0027 inline std::ostream &operator<<(std::ostream &os, enum ol_errc_t value);
0028 inline std::ostream &operator<<(std::ostream &os,
0029 enum ol_platform_info_t value);
0030 inline std::ostream &operator<<(std::ostream &os,
0031 enum ol_platform_backend_t value);
0032 inline std::ostream &operator<<(std::ostream &os, enum ol_device_type_t value);
0033 inline std::ostream &operator<<(std::ostream &os, enum ol_device_info_t value);
0034
0035
0036
0037
0038 inline std::ostream &operator<<(std::ostream &os, enum ol_errc_t value) {
0039 switch (value) {
0040 case OL_ERRC_SUCCESS:
0041 os << "OL_ERRC_SUCCESS";
0042 break;
0043 case OL_ERRC_INVALID_VALUE:
0044 os << "OL_ERRC_INVALID_VALUE";
0045 break;
0046 case OL_ERRC_INVALID_PLATFORM:
0047 os << "OL_ERRC_INVALID_PLATFORM";
0048 break;
0049 case OL_ERRC_DEVICE_NOT_FOUND:
0050 os << "OL_ERRC_DEVICE_NOT_FOUND";
0051 break;
0052 case OL_ERRC_INVALID_DEVICE:
0053 os << "OL_ERRC_INVALID_DEVICE";
0054 break;
0055 case OL_ERRC_DEVICE_LOST:
0056 os << "OL_ERRC_DEVICE_LOST";
0057 break;
0058 case OL_ERRC_UNINITIALIZED:
0059 os << "OL_ERRC_UNINITIALIZED";
0060 break;
0061 case OL_ERRC_OUT_OF_RESOURCES:
0062 os << "OL_ERRC_OUT_OF_RESOURCES";
0063 break;
0064 case OL_ERRC_UNSUPPORTED_VERSION:
0065 os << "OL_ERRC_UNSUPPORTED_VERSION";
0066 break;
0067 case OL_ERRC_UNSUPPORTED_FEATURE:
0068 os << "OL_ERRC_UNSUPPORTED_FEATURE";
0069 break;
0070 case OL_ERRC_INVALID_ARGUMENT:
0071 os << "OL_ERRC_INVALID_ARGUMENT";
0072 break;
0073 case OL_ERRC_INVALID_NULL_HANDLE:
0074 os << "OL_ERRC_INVALID_NULL_HANDLE";
0075 break;
0076 case OL_ERRC_INVALID_NULL_POINTER:
0077 os << "OL_ERRC_INVALID_NULL_POINTER";
0078 break;
0079 case OL_ERRC_INVALID_SIZE:
0080 os << "OL_ERRC_INVALID_SIZE";
0081 break;
0082 case OL_ERRC_INVALID_ENUMERATION:
0083 os << "OL_ERRC_INVALID_ENUMERATION";
0084 break;
0085 case OL_ERRC_UNSUPPORTED_ENUMERATION:
0086 os << "OL_ERRC_UNSUPPORTED_ENUMERATION";
0087 break;
0088 case OL_ERRC_UNKNOWN:
0089 os << "OL_ERRC_UNKNOWN";
0090 break;
0091 default:
0092 os << "unknown enumerator";
0093 break;
0094 }
0095 return os;
0096 }
0097
0098
0099
0100
0101 inline std::ostream &operator<<(std::ostream &os,
0102 enum ol_platform_info_t value) {
0103 switch (value) {
0104 case OL_PLATFORM_INFO_NAME:
0105 os << "OL_PLATFORM_INFO_NAME";
0106 break;
0107 case OL_PLATFORM_INFO_VENDOR_NAME:
0108 os << "OL_PLATFORM_INFO_VENDOR_NAME";
0109 break;
0110 case OL_PLATFORM_INFO_VERSION:
0111 os << "OL_PLATFORM_INFO_VERSION";
0112 break;
0113 case OL_PLATFORM_INFO_BACKEND:
0114 os << "OL_PLATFORM_INFO_BACKEND";
0115 break;
0116 default:
0117 os << "unknown enumerator";
0118 break;
0119 }
0120 return os;
0121 }
0122
0123
0124
0125
0126 template <>
0127 inline void printTagged(std::ostream &os, const void *ptr,
0128 ol_platform_info_t value, size_t size) {
0129 if (ptr == NULL) {
0130 printPtr(os, ptr);
0131 return;
0132 }
0133
0134 switch (value) {
0135 case OL_PLATFORM_INFO_NAME: {
0136 printPtr(os, (const char *)ptr);
0137 break;
0138 }
0139 case OL_PLATFORM_INFO_VENDOR_NAME: {
0140 printPtr(os, (const char *)ptr);
0141 break;
0142 }
0143 case OL_PLATFORM_INFO_VERSION: {
0144 printPtr(os, (const char *)ptr);
0145 break;
0146 }
0147 case OL_PLATFORM_INFO_BACKEND: {
0148 const ol_platform_backend_t *const tptr =
0149 (const ol_platform_backend_t *const)ptr;
0150 os << (const void *)tptr << " (";
0151 os << *tptr;
0152 os << ")";
0153 break;
0154 }
0155 default:
0156 os << "unknown enumerator";
0157 break;
0158 }
0159 }
0160
0161
0162
0163 inline std::ostream &operator<<(std::ostream &os,
0164 enum ol_platform_backend_t value) {
0165 switch (value) {
0166 case OL_PLATFORM_BACKEND_UNKNOWN:
0167 os << "OL_PLATFORM_BACKEND_UNKNOWN";
0168 break;
0169 case OL_PLATFORM_BACKEND_CUDA:
0170 os << "OL_PLATFORM_BACKEND_CUDA";
0171 break;
0172 case OL_PLATFORM_BACKEND_AMDGPU:
0173 os << "OL_PLATFORM_BACKEND_AMDGPU";
0174 break;
0175 default:
0176 os << "unknown enumerator";
0177 break;
0178 }
0179 return os;
0180 }
0181
0182
0183
0184
0185 inline std::ostream &operator<<(std::ostream &os, enum ol_device_type_t value) {
0186 switch (value) {
0187 case OL_DEVICE_TYPE_DEFAULT:
0188 os << "OL_DEVICE_TYPE_DEFAULT";
0189 break;
0190 case OL_DEVICE_TYPE_ALL:
0191 os << "OL_DEVICE_TYPE_ALL";
0192 break;
0193 case OL_DEVICE_TYPE_GPU:
0194 os << "OL_DEVICE_TYPE_GPU";
0195 break;
0196 case OL_DEVICE_TYPE_CPU:
0197 os << "OL_DEVICE_TYPE_CPU";
0198 break;
0199 default:
0200 os << "unknown enumerator";
0201 break;
0202 }
0203 return os;
0204 }
0205
0206
0207
0208
0209 inline std::ostream &operator<<(std::ostream &os, enum ol_device_info_t value) {
0210 switch (value) {
0211 case OL_DEVICE_INFO_TYPE:
0212 os << "OL_DEVICE_INFO_TYPE";
0213 break;
0214 case OL_DEVICE_INFO_PLATFORM:
0215 os << "OL_DEVICE_INFO_PLATFORM";
0216 break;
0217 case OL_DEVICE_INFO_NAME:
0218 os << "OL_DEVICE_INFO_NAME";
0219 break;
0220 case OL_DEVICE_INFO_VENDOR:
0221 os << "OL_DEVICE_INFO_VENDOR";
0222 break;
0223 case OL_DEVICE_INFO_DRIVER_VERSION:
0224 os << "OL_DEVICE_INFO_DRIVER_VERSION";
0225 break;
0226 default:
0227 os << "unknown enumerator";
0228 break;
0229 }
0230 return os;
0231 }
0232
0233
0234
0235
0236 template <>
0237 inline void printTagged(std::ostream &os, const void *ptr,
0238 ol_device_info_t value, size_t size) {
0239 if (ptr == NULL) {
0240 printPtr(os, ptr);
0241 return;
0242 }
0243
0244 switch (value) {
0245 case OL_DEVICE_INFO_TYPE: {
0246 const ol_device_type_t *const tptr = (const ol_device_type_t *const)ptr;
0247 os << (const void *)tptr << " (";
0248 os << *tptr;
0249 os << ")";
0250 break;
0251 }
0252 case OL_DEVICE_INFO_PLATFORM: {
0253 const ol_platform_handle_t *const tptr =
0254 (const ol_platform_handle_t *const)ptr;
0255 os << (const void *)tptr << " (";
0256 os << *tptr;
0257 os << ")";
0258 break;
0259 }
0260 case OL_DEVICE_INFO_NAME: {
0261 printPtr(os, (const char *)ptr);
0262 break;
0263 }
0264 case OL_DEVICE_INFO_VENDOR: {
0265 printPtr(os, (const char *)ptr);
0266 break;
0267 }
0268 case OL_DEVICE_INFO_DRIVER_VERSION: {
0269 printPtr(os, (const char *)ptr);
0270 break;
0271 }
0272 default:
0273 os << "unknown enumerator";
0274 break;
0275 }
0276 }
0277
0278 inline std::ostream &operator<<(std::ostream &os,
0279 const ol_error_struct_t *Err) {
0280 if (Err == nullptr) {
0281 os << "OL_SUCCESS";
0282 } else {
0283 os << Err->Code;
0284 }
0285 return os;
0286 }
0287
0288 inline std::ostream &operator<<(std::ostream &os,
0289 const struct ol_get_platform_params_t *params) {
0290 os << ".NumEntries = ";
0291 os << *params->pNumEntries;
0292 os << ", ";
0293 os << ".Platforms = ";
0294 os << "{";
0295 for (size_t i = 0; i < *params->pNumEntries; i++) {
0296 if (i > 0) {
0297 os << ", ";
0298 }
0299 printPtr(os, (*params->pPlatforms)[i]);
0300 }
0301 os << "}";
0302 return os;
0303 }
0304
0305 inline std::ostream &
0306 operator<<(std::ostream &os,
0307 const struct ol_get_platform_count_params_t *params) {
0308 os << ".NumPlatforms = ";
0309 printPtr(os, *params->pNumPlatforms);
0310 return os;
0311 }
0312
0313 inline std::ostream &
0314 operator<<(std::ostream &os,
0315 const struct ol_get_platform_info_params_t *params) {
0316 os << ".Platform = ";
0317 printPtr(os, *params->pPlatform);
0318 os << ", ";
0319 os << ".PropName = ";
0320 os << *params->pPropName;
0321 os << ", ";
0322 os << ".PropSize = ";
0323 os << *params->pPropSize;
0324 os << ", ";
0325 os << ".PropValue = ";
0326 printTagged(os, *params->pPropValue, *params->pPropName, *params->pPropSize);
0327 return os;
0328 }
0329
0330 inline std::ostream &
0331 operator<<(std::ostream &os,
0332 const struct ol_get_platform_info_size_params_t *params) {
0333 os << ".Platform = ";
0334 printPtr(os, *params->pPlatform);
0335 os << ", ";
0336 os << ".PropName = ";
0337 os << *params->pPropName;
0338 os << ", ";
0339 os << ".PropSizeRet = ";
0340 printPtr(os, *params->pPropSizeRet);
0341 return os;
0342 }
0343
0344 inline std::ostream &
0345 operator<<(std::ostream &os,
0346 const struct ol_get_device_count_params_t *params) {
0347 os << ".Platform = ";
0348 printPtr(os, *params->pPlatform);
0349 os << ", ";
0350 os << ".NumDevices = ";
0351 printPtr(os, *params->pNumDevices);
0352 return os;
0353 }
0354
0355 inline std::ostream &operator<<(std::ostream &os,
0356 const struct ol_get_device_params_t *params) {
0357 os << ".Platform = ";
0358 printPtr(os, *params->pPlatform);
0359 os << ", ";
0360 os << ".NumEntries = ";
0361 os << *params->pNumEntries;
0362 os << ", ";
0363 os << ".Devices = ";
0364 os << "{";
0365 for (size_t i = 0; i < *params->pNumEntries; i++) {
0366 if (i > 0) {
0367 os << ", ";
0368 }
0369 printPtr(os, (*params->pDevices)[i]);
0370 }
0371 os << "}";
0372 return os;
0373 }
0374
0375 inline std::ostream &
0376 operator<<(std::ostream &os, const struct ol_get_device_info_params_t *params) {
0377 os << ".Device = ";
0378 printPtr(os, *params->pDevice);
0379 os << ", ";
0380 os << ".PropName = ";
0381 os << *params->pPropName;
0382 os << ", ";
0383 os << ".PropSize = ";
0384 os << *params->pPropSize;
0385 os << ", ";
0386 os << ".PropValue = ";
0387 printTagged(os, *params->pPropValue, *params->pPropName, *params->pPropSize);
0388 return os;
0389 }
0390
0391 inline std::ostream &
0392 operator<<(std::ostream &os,
0393 const struct ol_get_device_info_size_params_t *params) {
0394 os << ".Device = ";
0395 printPtr(os, *params->pDevice);
0396 os << ", ";
0397 os << ".PropName = ";
0398 os << *params->pPropName;
0399 os << ", ";
0400 os << ".PropSizeRet = ";
0401 printPtr(os, *params->pPropSizeRet);
0402 return os;
0403 }
0404
0405
0406
0407 template <typename T>
0408 inline ol_result_t printPtr(std::ostream &os, const T *ptr) {
0409 if (ptr == nullptr) {
0410 os << "nullptr";
0411 } else if constexpr (std::is_pointer_v<T>) {
0412 os << (const void *)(ptr) << " (";
0413 printPtr(os, *ptr);
0414 os << ")";
0415 } else if constexpr (std::is_void_v<T> || is_handle_v<T *>) {
0416 os << (const void *)ptr;
0417 } else if constexpr (std::is_same_v<std::remove_cv_t<T>, char>) {
0418 os << (const void *)(ptr) << " (";
0419 os << ptr;
0420 os << ")";
0421 } else {
0422 os << (const void *)(ptr) << " (";
0423 os << *ptr;
0424 os << ")";
0425 }
0426
0427 return OL_SUCCESS;
0428 }