1313
1414#include " PluginManager.h"
1515#include " helpers.hpp"
16+ #include " offload_impl.hpp"
1617#include " llvm/Support/FormatVariadic.h"
1718#include < offload_api.h>
1819
@@ -66,17 +67,37 @@ void initPlugins() {
6667 }
6768}
6869
69- offload_result_t offloadPlatformGet_impl (uint32_t NumEntries,
70- offload_platform_handle_t *phPlatforms,
71- uint32_t *pNumPlatforms) {
70+ offload_result_t offloadGetErrorDetails_impl (size_t *SizeRet,
71+ const char **DetailStringRet) {
72+ if (auto Details = LastErrorDetails ()) {
73+ if (SizeRet) {
74+ *SizeRet = Details->size ();
75+ }
76+ if (DetailStringRet) {
77+ *DetailStringRet = Details->c_str ();
78+ }
79+ } else {
80+ if (SizeRet) {
81+ *SizeRet = 0 ;
82+ }
83+ }
84+ return OFFLOAD_RESULT_SUCCESS;
85+ }
86+
87+ offload_impl_result_t
88+ offloadPlatformGet_impl (uint32_t NumEntries,
89+ offload_platform_handle_t *phPlatforms,
90+ uint32_t *pNumPlatforms) {
7291 // It is expected that offloadPlatformGet is the first function to be called.
7392 // In future it may make sense to have a specific entry point for Offload
7493 // initialization, or expose explicit initialization of plugins.
7594 static std::once_flag InitFlag;
7695 std::call_once (InitFlag, initPlugins);
7796
7897 if (NumEntries > Platforms ().size ()) {
79- return OFFLOAD_RESULT_ERROR_INVALID_SIZE;
98+ return {OFFLOAD_RESULT_ERROR_INVALID_SIZE,
99+ formatv (" {0} platform(s) available but {1} requested." ,
100+ Platforms ().size (), NumEntries)};
80101 }
81102
82103 if (phPlatforms) {
@@ -93,7 +114,7 @@ offload_result_t offloadPlatformGet_impl(uint32_t NumEntries,
93114 return OFFLOAD_RESULT_SUCCESS;
94115}
95116
96- offload_result_t
117+ offload_impl_result_t
97118offloadPlatformGetInfo_impl (offload_platform_handle_t hPlatform,
98119 offload_platform_info_t propName, size_t propSize,
99120 void *pPropValue, size_t *pPropSizeRet) {
@@ -126,11 +147,11 @@ offloadPlatformGetInfo_impl(offload_platform_handle_t hPlatform,
126147 return OFFLOAD_RESULT_SUCCESS;
127148}
128149
129- offload_result_t offloadDeviceGet_impl (offload_platform_handle_t hPlatform,
130- offload_device_type_t ,
131- uint32_t NumEntries,
132- offload_device_handle_t *phDevices,
133- uint32_t *pNumDevices) {
150+ offload_impl_result_t offloadDeviceGet_impl (offload_platform_handle_t hPlatform,
151+ offload_device_type_t ,
152+ uint32_t NumEntries,
153+ offload_device_handle_t *phDevices,
154+ uint32_t *pNumDevices) {
134155
135156 if (phDevices) {
136157 for (uint32_t DeviceIndex = 0 ; DeviceIndex < NumEntries; DeviceIndex++) {
@@ -145,10 +166,11 @@ offload_result_t offloadDeviceGet_impl(offload_platform_handle_t hPlatform,
145166 return OFFLOAD_RESULT_SUCCESS;
146167}
147168
148- offload_result_t offloadDeviceGetInfo_impl (offload_device_handle_t hDevice,
149- offload_device_info_t propName,
150- size_t propSize, void *pPropValue,
151- size_t *pPropSizeRet) {
169+ offload_impl_result_t offloadDeviceGetInfo_impl (offload_device_handle_t hDevice,
170+ offload_device_info_t propName,
171+ size_t propSize,
172+ void *pPropValue,
173+ size_t *pPropSizeRet) {
152174
153175 ReturnHelper ReturnValue (propSize, pPropValue, pPropSizeRet);
154176
0 commit comments