Skip to content

Commit f5979a6

Browse files
committed
[Spec Constants] Improved handling of invalid/unsupported spec. constants
Two main changes to how `Kernel/ProgramSetSpecializationConstants` are handled: * They may now output either `INVALID_VALUE` or the new `INVALID_SPEC_ID` when the provided list is invalid. * The OpenCL and level 0 adapters now respond to `UR_DEVICE_INFO_KERNEL_SET_SPECIALIZATION_CONSTANTS` with `false` rather than erroring out. This fixes some tests that were incorrectly not being skipped. * `urKernelSetSpecializationConstants` now "implemented" (as a function that returns `UNSUPPORTED_FEATURE` for a number of adapters.
1 parent df6da35 commit f5979a6

21 files changed

+154
-6
lines changed

include/ur_api.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ typedef enum ur_result_t {
510510
UR_RESULT_ERROR_LAYER_NOT_PRESENT = 67, ///< A requested layer was not found by the loader.
511511
UR_RESULT_ERROR_IN_EVENT_LIST_EXEC_STATUS = 68, ///< An event in the provided wait list has ::UR_EVENT_STATUS_ERROR.
512512
UR_RESULT_ERROR_DEVICE_NOT_AVAILABLE = 69, ///< Device in question has `::UR_DEVICE_INFO_AVAILABLE == false`
513+
UR_RESULT_ERROR_INVALID_SPEC_ID = 70, ///< A specialization constant identifier is not valid.
513514
UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_EXP = 0x1000, ///< Invalid Command-Buffer
514515
UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_SYNC_POINT_EXP = 0x1001, ///< Sync point is not valid for the command-buffer
515516
UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_SYNC_POINT_WAIT_LIST_EXP = 0x1002, ///< Sync point wait list is invalid
@@ -4649,6 +4650,11 @@ typedef struct ur_specialization_constant_info_t {
46494650
/// + `NULL == pSpecConstants`
46504651
/// - ::UR_RESULT_ERROR_INVALID_SIZE
46514652
/// + `count == 0`
4653+
/// - ::UR_RESULT_ERROR_INVALID_VALUE
4654+
/// + A pSpecConstant entry contains a size that does not match that of the specialization constant in the module.
4655+
/// + A pSpecConstant entry contains a nullptr pValue.
4656+
/// - ::UR_RESULT_ERROR_INVALID_SPEC_ID
4657+
/// + Any id specified in a pSpecConstant entry is not a valid specialization constant identifier.
46524658
UR_APIEXPORT ur_result_t UR_APICALL
46534659
urProgramSetSpecializationConstants(
46544660
ur_program_handle_t hProgram, ///< [in] handle of the Program object
@@ -5240,6 +5246,11 @@ urKernelSetArgMemObj(
52405246
/// + `count == 0`
52415247
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
52425248
/// + If ::UR_DEVICE_INFO_KERNEL_SET_SPECIALIZATION_CONSTANTS query is false
5249+
/// - ::UR_RESULT_ERROR_INVALID_VALUE
5250+
/// + A pSpecConstant entry contains a size that does not match that of the specialization constant in the module.
5251+
/// + A pSpecConstant entry contains a nullptr pValue.
5252+
/// - ::UR_RESULT_ERROR_INVALID_SPEC_ID
5253+
/// + Any id specified in a pSpecConstant entry is not a valid specialization constant identifier.
52435254
UR_APIEXPORT ur_result_t UR_APICALL
52445255
urKernelSetSpecializationConstants(
52455256
ur_kernel_handle_t hKernel, ///< [in] handle of the kernel object

include/ur_print.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,9 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_result_t value) {
15911591
case UR_RESULT_ERROR_DEVICE_NOT_AVAILABLE:
15921592
os << "UR_RESULT_ERROR_DEVICE_NOT_AVAILABLE";
15931593
break;
1594+
case UR_RESULT_ERROR_INVALID_SPEC_ID:
1595+
os << "UR_RESULT_ERROR_INVALID_SPEC_ID";
1596+
break;
15941597
case UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_EXP:
15951598
os << "UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_EXP";
15961599
break;

scripts/core/common.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ etors:
282282
desc: "An event in the provided wait list has $X_EVENT_STATUS_ERROR."
283283
- name: ERROR_DEVICE_NOT_AVAILABLE
284284
desc: "Device in question has `$X_DEVICE_INFO_AVAILABLE == false`"
285+
- name: ERROR_INVALID_SPEC_ID
286+
desc: "A specialization constant identifier is not valid."
285287
- name: ERROR_UNKNOWN
286288
value: "0x7ffffffe"
287289
desc: "Unknown or internal error"

scripts/core/kernel.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,11 @@ returns:
475475
- "`count == 0`"
476476
- $X_RESULT_ERROR_UNSUPPORTED_FEATURE:
477477
- "If $X_DEVICE_INFO_KERNEL_SET_SPECIALIZATION_CONSTANTS query is false"
478+
- $X_RESULT_ERROR_INVALID_VALUE:
479+
- "A pSpecConstant entry contains a size that does not match that of the specialization constant in the module."
480+
- "A pSpecConstant entry contains a nullptr pValue."
481+
- $X_RESULT_ERROR_INVALID_SPEC_ID:
482+
- "Any id specified in a pSpecConstant entry is not a valid specialization constant identifier."
478483
--- #--------------------------------------------------------------------------
479484
type: function
480485
desc: "Return platform native kernel handle."

scripts/core/program.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,11 @@ params:
542542
returns:
543543
- $X_RESULT_ERROR_INVALID_SIZE:
544544
- "`count == 0`"
545+
- $X_RESULT_ERROR_INVALID_VALUE:
546+
- "A pSpecConstant entry contains a size that does not match that of the specialization constant in the module."
547+
- "A pSpecConstant entry contains a nullptr pValue."
548+
- $X_RESULT_ERROR_INVALID_SPEC_ID:
549+
- "Any id specified in a pSpecConstant entry is not a valid specialization constant identifier."
545550
--- #--------------------------------------------------------------------------
546551
type: function
547552
desc: "Return program native program handle."

source/adapters/cuda/kernel.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,3 +472,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelGetSuggestedLocalWorkSize(
472472
pSuggestedLocalWorkSize);
473473
return Result;
474474
}
475+
476+
UR_APIEXPORT ur_result_t UR_APICALL urKernelSetSpecializationConstants(
477+
ur_kernel_handle_t, uint32_t, const ur_specialization_constant_info_t *) {
478+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
479+
}

source/adapters/cuda/ur_interface_loader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetKernelProcAddrTable(
124124
pDdiTable->pfnSetArgSampler = urKernelSetArgSampler;
125125
pDdiTable->pfnSetArgValue = urKernelSetArgValue;
126126
pDdiTable->pfnSetExecInfo = urKernelSetExecInfo;
127-
pDdiTable->pfnSetSpecializationConstants = nullptr;
127+
pDdiTable->pfnSetSpecializationConstants = urKernelSetSpecializationConstants;
128128
pDdiTable->pfnGetSuggestedLocalWorkSize = urKernelGetSuggestedLocalWorkSize;
129129
return UR_RESULT_SUCCESS;
130130
}

source/adapters/native_cpu/kernel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelSetSpecializationConstants(
286286
std::ignore = count;
287287
std::ignore = pSpecConstants;
288288

289-
DIE_NO_IMPLEMENTATION
289+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
290290
}
291291

292292
UR_APIEXPORT ur_result_t UR_APICALL urKernelGetNativeHandle(

source/adapters/opencl/common.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ ur_result_t mapCLErrorToUR(cl_int Result) {
9595
return UR_RESULT_ERROR_INVALID_QUEUE;
9696
case CL_INVALID_ARG_SIZE:
9797
return UR_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_SIZE;
98+
case CL_INVALID_SPEC_ID:
99+
return UR_RESULT_ERROR_INVALID_SPEC_ID;
98100
default:
99101
return UR_RESULT_ERROR_UNKNOWN;
100102
}

source/adapters/opencl/kernel.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,3 +427,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelGetSuggestedLocalWorkSize(
427427
pGlobalWorkSize, pSuggestedLocalWorkSize));
428428
return UR_RESULT_SUCCESS;
429429
}
430+
431+
UR_APIEXPORT ur_result_t UR_APICALL urKernelSetSpecializationConstants(
432+
ur_kernel_handle_t, uint32_t, const ur_specialization_constant_info_t *) {
433+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
434+
}

0 commit comments

Comments
 (0)