Skip to content

Commit d01369e

Browse files
author
Diptorup Deb
authored
Merge pull request #492 from diptorupd/fix/c_api_queue_tests
Improve test coverage for dpctl_sycl_queue_interface
2 parents 227a126 + 57488e1 commit d01369e

File tree

4 files changed

+296
-239
lines changed

4 files changed

+296
-239
lines changed

dpctl-capi/source/dpctl_sycl_program_interface.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,16 @@ createLevelZeroInterOpProgram(const context &SyclCtx,
164164

165165
auto stZeModuleCreateF = getZeModuleCreateFn();
166166

167-
if (!stZeModuleCreateF)
167+
if (!stZeModuleCreateF) {
168+
std::cerr << "ZeModuleCreateFn is invalid.\n";
168169
return nullptr;
170+
}
169171

170172
auto ret =
171173
stZeModuleCreateF(ZeCtx, ZeDevice, &ZeModuleDesc, &ZeModule, nullptr);
172174
if (ret != ZE_RESULT_SUCCESS) {
173175
// TODO: handle error
176+
std::cerr << "ZeModule creation failed.\n";
174177
return nullptr;
175178
}
176179

@@ -199,6 +202,8 @@ DPCTLProgram_CreateFromSpirv(__dpctl_keep const DPCTLSyclContextRef CtxRef,
199202
context *SyclCtx = nullptr;
200203
if (!CtxRef) {
201204
// \todo handle error
205+
std::cerr << "Cannot create program from SPIR-V as the supplied SYCL "
206+
"context is NULL.\n";
202207
return Pref;
203208
}
204209
SyclCtx = unwrap(CtxRef);

dpctl-capi/source/dpctl_sycl_queue_interface.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -294,14 +294,18 @@ bool DPCTLQueue_AreEq(__dpctl_keep const DPCTLSyclQueueRef QRef1,
294294
DPCTLSyclBackendType DPCTLQueue_GetBackend(__dpctl_keep DPCTLSyclQueueRef QRef)
295295
{
296296
auto Q = unwrap(QRef);
297-
try {
298-
auto C = Q->get_context();
299-
return DPCTLContext_GetBackend(wrap(&C));
300-
} catch (runtime_error &re) {
301-
std::cerr << re.what() << '\n';
302-
// store error message
303-
return DPCTL_UNKNOWN_BACKEND;
297+
if (Q) {
298+
try {
299+
auto C = Q->get_context();
300+
return DPCTLContext_GetBackend(wrap(&C));
301+
} catch (runtime_error &re) {
302+
std::cerr << re.what() << '\n';
303+
// store error message
304+
return DPCTL_UNKNOWN_BACKEND;
305+
}
304306
}
307+
else
308+
return DPCTL_UNKNOWN_BACKEND;
305309
}
306310

307311
__dpctl_give DPCTLSyclDeviceRef
@@ -327,8 +331,13 @@ __dpctl_give DPCTLSyclContextRef
327331
DPCTLQueue_GetContext(__dpctl_keep const DPCTLSyclQueueRef QRef)
328332
{
329333
auto Q = unwrap(QRef);
330-
auto Context = new context(Q->get_context());
331-
return wrap(Context);
334+
DPCTLSyclContextRef CRef = nullptr;
335+
if (Q)
336+
CRef = wrap(new context(Q->get_context()));
337+
else {
338+
std::cerr << "Could not get the context for this queue.\n";
339+
}
340+
return CRef;
332341
}
333342

334343
__dpctl_give DPCTLSyclEventRef

0 commit comments

Comments
 (0)