Skip to content

Commit

Permalink
Return more accurate errors from CL's ProgramCreateWithIL
Browse files Browse the repository at this point in the history
clCreateProgramWithIL only returns CL_INVALID_VALUE in three specific
cirumstances, based on this we can deduce a more informative error code
when we get that return.

Fixes the urProgramCreateWithILTest.BuildInvalidProgram cts test.
  • Loading branch information
aarongreig committed Sep 27, 2024
1 parent e824ddc commit 041c80d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
19 changes: 18 additions & 1 deletion source/adapters/opencl/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithIL(

*phProgram = cl_adapter::cast<ur_program_handle_t>(clCreateProgramWithIL(
cl_adapter::cast<cl_context>(hContext), pIL, length, &Err));
CL_RETURN_ON_FAILURE(Err);
} else {

/* If none of the devices conform with CL 2.1 or newer make sure they all
Expand Down Expand Up @@ -109,6 +108,24 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithIL(

*phProgram = cl_adapter::cast<ur_program_handle_t>(
FuncPtr(cl_adapter::cast<cl_context>(hContext), pIL, length, &Err));
}

// INVALID_VALUE is only returned in three circumstances according to the cl
// spec:
// * pIL == NULL
// * length == 0
// * pIL is not a well-formed binary
// UR has a unique error code for each of these, so here we figure out which
// to return
if (Err == CL_INVALID_VALUE) {
if (pIL == nullptr) {
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
}
if (length == 0) {
return UR_RESULT_ERROR_INVALID_SIZE;
}
return UR_RESULT_ERROR_INVALID_BINARY;
} else {
CL_RETURN_ON_FAILURE(Err);
}

Expand Down
1 change: 0 additions & 1 deletion test/conformance/program/program_adapter_opencl.match
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
{{NONDETERMINISTIC}}
urProgramCreateWithILTest.BuildInvalidProgram/Intel_R__OpenCL___{{.*}}_
urProgramGetInfoTest.Success/Intel_R__OpenCL___{{.*}}___UR_PROGRAM_INFO_SOURCE

0 comments on commit 041c80d

Please sign in to comment.