Skip to content

Commit b074893

Browse files
authored
Merge pull request #2539 from RossBrunton/ross/specconst
Added `DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS`
2 parents 71a5eab + 128ea02 commit b074893

File tree

14 files changed

+117
-13
lines changed

14 files changed

+117
-13
lines changed

include/ur_api.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,6 +2198,9 @@ typedef enum ur_device_info_t {
21982198
/// to the `USMPool` entry points and usage of the `pool` parameter of the
21992199
/// USM alloc entry points.
22002200
UR_DEVICE_INFO_USM_POOL_SUPPORT = 119,
2201+
/// [::ur_bool_t] support the ::urProgramSetSpecializationConstants entry
2202+
/// point
2203+
UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS = 120,
22012204
/// [::ur_bool_t] Returns true if the device supports the use of
22022205
/// command-buffers.
22032206
UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP = 0x1000,
@@ -5739,6 +5742,10 @@ typedef struct ur_specialization_constant_info_t {
57395742
/// @brief Set an array of specialization constants on a Program.
57405743
///
57415744
/// @details
5745+
/// - This entry point is optional, the application should query for support
5746+
/// with device query
5747+
/// ::UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS passed to
5748+
/// ::urDeviceGetInfo.
57425749
/// - The application may call this function from simultaneous threads for
57435750
/// the same device.
57445751
/// - The implementation of this function should be thread-safe.
@@ -5758,6 +5765,9 @@ typedef struct ur_specialization_constant_info_t {
57585765
/// + `NULL == pSpecConstants`
57595766
/// - ::UR_RESULT_ERROR_INVALID_SIZE
57605767
/// + `count == 0`
5768+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
5769+
/// + If ::UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS query is
5770+
/// false
57615771
/// - ::UR_RESULT_ERROR_INVALID_VALUE
57625772
/// + A pSpecConstant entry contains a size that does not match that of
57635773
/// the specialization constant in the module.

include/ur_print.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2917,6 +2917,9 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_device_info_t value) {
29172917
case UR_DEVICE_INFO_USM_POOL_SUPPORT:
29182918
os << "UR_DEVICE_INFO_USM_POOL_SUPPORT";
29192919
break;
2920+
case UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS:
2921+
os << "UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS";
2922+
break;
29202923
case UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP:
29212924
os << "UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP";
29222925
break;
@@ -4548,6 +4551,19 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr,
45484551

45494552
os << ")";
45504553
} break;
4554+
case UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS: {
4555+
const ur_bool_t *tptr = (const ur_bool_t *)ptr;
4556+
if (sizeof(ur_bool_t) > size) {
4557+
os << "invalid size (is: " << size
4558+
<< ", expected: >=" << sizeof(ur_bool_t) << ")";
4559+
return UR_RESULT_ERROR_INVALID_SIZE;
4560+
}
4561+
os << (const void *)(tptr) << " (";
4562+
4563+
os << *tptr;
4564+
4565+
os << ")";
4566+
} break;
45514567
case UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP: {
45524568
const ur_bool_t *tptr = (const ur_bool_t *)ptr;
45534569
if (sizeof(ur_bool_t) > size) {

scripts/core/device.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,8 @@ etors:
443443
desc: "[$x_bool_t] return true if the device supports the `EnqueueDeviceGlobalVariableWrite` and `EnqueueDeviceGlobalVariableRead` entry points."
444444
- name: USM_POOL_SUPPORT
445445
desc: "[$x_bool_t] return true if the device supports USM pooling. Pertains to the `USMPool` entry points and usage of the `pool` parameter of the USM alloc entry points."
446+
- name: PROGRAM_SET_SPECIALIZATION_CONSTANTS
447+
desc: "[$x_bool_t] support the $xProgramSetSpecializationConstants entry point"
446448
--- #--------------------------------------------------------------------------
447449
type: function
448450
desc: "Retrieves various information about device"

scripts/core/program.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ desc: "Set an array of specialization constants on a Program."
528528
class: $xProgram
529529
name: SetSpecializationConstants
530530
details:
531+
- "This entry point is optional, the application should query for support with device query $X_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS passed to $xDeviceGetInfo."
531532
- "The application may call this function from simultaneous threads for the same device."
532533
- "The implementation of this function should be thread-safe."
533534
- "`hProgram` must have been created with the $xProgramCreateWithIL entry point."
@@ -546,6 +547,8 @@ params:
546547
returns:
547548
- $X_RESULT_ERROR_INVALID_SIZE:
548549
- "`count == 0`"
550+
- $X_RESULT_ERROR_UNSUPPORTED_FEATURE:
551+
- "If $X_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS query is false"
549552
- $X_RESULT_ERROR_INVALID_VALUE:
550553
- "A pSpecConstant entry contains a size that does not match that of the specialization constant in the module."
551554
- "A pSpecConstant entry contains a nullptr pValue."

source/adapters/cuda/device.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
10651065
return ReturnValue(AddressBuffer,
10661066
strnlen(AddressBuffer, AddressBufferSize - 1) + 1);
10671067
}
1068+
case UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS:
10681069
case UR_DEVICE_INFO_KERNEL_SET_SPECIALIZATION_CONSTANTS:
10691070
return ReturnValue(static_cast<ur_bool_t>(false));
10701071
// TODO: Investigate if this information is available on CUDA.

source/adapters/hip/device.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
789789
return ReturnValue(ur_bool_t{false});
790790
}
791791

792+
case UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS: {
793+
return ReturnValue(ur_bool_t{false});
794+
}
795+
792796
case UR_DEVICE_INFO_ATOMIC_MEMORY_ORDER_CAPABILITIES: {
793797
ur_memory_order_capability_flags_t Capabilities =
794798
UR_MEMORY_ORDER_CAPABILITY_FLAG_RELAXED |

source/adapters/level_zero/device.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,8 @@ ur_result_t urDeviceGetInfo(
11561156
// L0 does not support sampling 1D USM sampled image data.
11571157
return ReturnValue(false);
11581158
}
1159+
case UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS:
1160+
return ReturnValue(true);
11591161
case UR_DEVICE_INFO_KERNEL_SET_SPECIALIZATION_CONSTANTS:
11601162
return ReturnValue(false);
11611163
case UR_DEVICE_INFO_GLOBAL_VARIABLE_SUPPORT:

source/adapters/native_cpu/device.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
428428

429429
case UR_DEVICE_INFO_LOW_POWER_EVENTS_EXP:
430430
return ReturnValue(false);
431+
432+
case UR_DEVICE_INFO_KERNEL_SET_SPECIALIZATION_CONSTANTS:
433+
case UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS:
434+
return ReturnValue(false);
435+
431436
default:
432437
DIE_NO_IMPLEMENTATION;
433438
}

source/adapters/opencl/device.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===-----------------------------------------------------------------===//
88

99
#include "device.hpp"
10+
#include "adapter.hpp"
1011
#include "common.hpp"
1112
#include "platform.hpp"
1213

@@ -1125,6 +1126,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
11251126
return ReturnValue(UUID);
11261127
}
11271128

1129+
case UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS: {
1130+
return ReturnValue(
1131+
ur::cl::getAdapter()->clSetProgramSpecializationConstant != nullptr);
1132+
}
1133+
11281134
// We can't query to check if these are supported, they will need to be
11291135
// manually updated if support is ever implemented.
11301136
case UR_DEVICE_INFO_KERNEL_SET_SPECIALIZATION_CONSTANTS:

source/loader/ur_libapi.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3543,6 +3543,10 @@ ur_result_t UR_APICALL urProgramGetBuildInfo(
35433543
/// @brief Set an array of specialization constants on a Program.
35443544
///
35453545
/// @details
3546+
/// - This entry point is optional, the application should query for support
3547+
/// with device query
3548+
/// ::UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS passed to
3549+
/// ::urDeviceGetInfo.
35463550
/// - The application may call this function from simultaneous threads for
35473551
/// the same device.
35483552
/// - The implementation of this function should be thread-safe.
@@ -3562,6 +3566,9 @@ ur_result_t UR_APICALL urProgramGetBuildInfo(
35623566
/// + `NULL == pSpecConstants`
35633567
/// - ::UR_RESULT_ERROR_INVALID_SIZE
35643568
/// + `count == 0`
3569+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
3570+
/// + If ::UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS query is
3571+
/// false
35653572
/// - ::UR_RESULT_ERROR_INVALID_VALUE
35663573
/// + A pSpecConstant entry contains a size that does not match that of
35673574
/// the specialization constant in the module.

0 commit comments

Comments
 (0)