Skip to content

Commit 872264a

Browse files
committed
Return Error from GetInfoXYZ
1 parent 95a5f19 commit 872264a

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

offload/liboffload/src/OffloadImpl.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
#include "OffloadImpl.hpp"
1515
#include "Helpers.hpp"
16+
// Required for operator<< implementation of ol_device_info_t
17+
#include "OffloadPrint.hpp"
1618
#include "PluginManager.h"
1719
#include "llvm/Support/FormatVariadic.h"
1820
#include <OffloadAPI.h>
@@ -264,13 +266,16 @@ Error olGetDeviceInfoImplDetail(ol_device_handle_t Device,
264266

265267
return "";
266268
};
267-
auto GetInfoXyz = [&](std::vector<std::string> Names) {
268-
if (!Device->Device)
269-
return ol_dimensions_t{0, 0, 0};
269+
auto GetInfoXyz = [&](std::vector<std::string> Names) -> Error {
270+
if (Device == OffloadContext::get().HostDevice())
271+
return ReturnValue(ol_dimensions_t{0u, 0u, 0u});
272+
273+
assert(Device->Device &&
274+
"liboffload device handle contains a null plugin device");
270275

271276
auto Info = Device->Device->obtainInfoImpl();
272277
if (auto Err = Info.takeError())
273-
return ol_dimensions_t{0, 0, 0};
278+
return Err;
274279

275280
for (auto Name : Names) {
276281
if (auto Entry = Info->get(Name)) {
@@ -283,11 +288,14 @@ Error olGetDeviceInfoImplDetail(ol_device_handle_t Device,
283288
Out.y = std::get<size_t>((*Y)->Value);
284289
if (auto Z = Node->get("z"))
285290
Out.z = std::get<size_t>((*Z)->Value);
286-
return Out;
291+
return ReturnValue(Out);
287292
}
288293
}
289294

290-
return ol_dimensions_t{0, 0, 0};
295+
std::string ErrBuffer;
296+
llvm::raw_string_ostream(ErrBuffer)
297+
<< "plugin did not provide information for " << PropName;
298+
return Plugin::error(ErrorCode::UNIMPLEMENTED, ErrBuffer.c_str());
291299
};
292300

293301
switch (PropName) {
@@ -305,8 +313,8 @@ Error olGetDeviceInfoImplDetail(ol_device_handle_t Device,
305313
return ReturnValue(
306314
GetInfoString({"CUDA Driver Version", "HSA Runtime Version"}));
307315
case OL_DEVICE_INFO_MAX_WORK_GROUP_SIZE:
308-
return ReturnValue(GetInfoXyz({"Workgroup Max Size per Dimension" /*AMD*/,
309-
"Maximum Block Dimensions" /*CUDA*/}));
316+
return GetInfoXyz({"Workgroup Max Size per Dimension" /*AMD*/,
317+
"Maximum Block Dimensions" /*CUDA*/});
310318
default:
311319
return createOffloadError(ErrorCode::INVALID_ENUMERATION,
312320
"getDeviceInfo enum '%i' is invalid", PropName);

0 commit comments

Comments
 (0)