Skip to content

Commit b074893

Browse files
authored
Merge pull request intel#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.

source/ur_api.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3109,6 +3109,10 @@ ur_result_t UR_APICALL urProgramGetBuildInfo(
31093109
/// @brief Set an array of specialization constants on a Program.
31103110
///
31113111
/// @details
3112+
/// - This entry point is optional, the application should query for support
3113+
/// with device query
3114+
/// ::UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS passed to
3115+
/// ::urDeviceGetInfo.
31123116
/// - The application may call this function from simultaneous threads for
31133117
/// the same device.
31143118
/// - The implementation of this function should be thread-safe.
@@ -3128,6 +3132,9 @@ ur_result_t UR_APICALL urProgramGetBuildInfo(
31283132
/// + `NULL == pSpecConstants`
31293133
/// - ::UR_RESULT_ERROR_INVALID_SIZE
31303134
/// + `count == 0`
3135+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
3136+
/// + If ::UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS query is
3137+
/// false
31313138
/// - ::UR_RESULT_ERROR_INVALID_VALUE
31323139
/// + A pSpecConstant entry contains a size that does not match that of
31333140
/// the specialization constant in the module.

test/conformance/device/urDeviceGetInfo.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ static std::unordered_map<ur_device_info_t, size_t> device_info_size_map = {
110110
{UR_DEVICE_INFO_BFLOAT16, sizeof(ur_bool_t)},
111111
{UR_DEVICE_INFO_MAX_COMPUTE_QUEUE_INDICES, sizeof(uint32_t)},
112112
{UR_DEVICE_INFO_KERNEL_SET_SPECIALIZATION_CONSTANTS, sizeof(ur_bool_t)},
113+
{UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS, sizeof(ur_bool_t)},
113114
{UR_DEVICE_INFO_MEMORY_BUS_WIDTH, sizeof(uint32_t)},
114115
{UR_DEVICE_INFO_MAX_WORK_GROUPS_3D, sizeof(size_t[3])},
115116
{UR_DEVICE_INFO_ASYNC_BARRIER, sizeof(ur_bool_t)},
@@ -251,7 +252,8 @@ UUR_DEVICE_TEST_SUITE_P(
251252
UR_DEVICE_INFO_2D_BLOCK_ARRAY_CAPABILITIES_EXP, //
252253
UR_DEVICE_INFO_PREFERRED_VECTOR_WIDTH_DOUBLE, //
253254
UR_DEVICE_INFO_PREFERRED_VECTOR_WIDTH_HALF, //
254-
UR_DEVICE_INFO_PREFERRED_VECTOR_WIDTH_INT //
255+
UR_DEVICE_INFO_PREFERRED_VECTOR_WIDTH_INT, //
256+
UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS //
255257
),
256258
uur::deviceTestWithParamPrinter<ur_device_info_t>);
257259

test/conformance/program/urProgramSetSpecializationConstants.cpp

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ struct urProgramSetSpecializationConstantsTest : uur::urKernelExecutionTest {
1111
void SetUp() override {
1212
program_name = "spec_constant";
1313
UUR_RETURN_ON_FATAL_FAILURE(urProgramTest::SetUp());
14+
15+
bool supports_kernel_spec_constant = false;
16+
ASSERT_SUCCESS(urDeviceGetInfo(
17+
device, UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS,
18+
sizeof(supports_kernel_spec_constant), &supports_kernel_spec_constant,
19+
nullptr));
20+
if (!supports_kernel_spec_constant) {
21+
GTEST_SKIP() << "Device does not support setting program spec constants.";
22+
}
1423
}
1524

1625
uint32_t spec_value = 42;
@@ -19,20 +28,50 @@ struct urProgramSetSpecializationConstantsTest : uur::urKernelExecutionTest {
1928
};
2029
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urProgramSetSpecializationConstantsTest);
2130

31+
struct urProgramSetSpecializationConstantsNegativeTest
32+
: uur::urKernelExecutionTest {
33+
void SetUp() override {
34+
program_name = "spec_constant";
35+
UUR_RETURN_ON_FATAL_FAILURE(urProgramTest::SetUp());
36+
37+
bool supports_kernel_spec_constant = false;
38+
ASSERT_SUCCESS(urDeviceGetInfo(
39+
device, UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS,
40+
sizeof(supports_kernel_spec_constant), &supports_kernel_spec_constant,
41+
nullptr));
42+
if (supports_kernel_spec_constant) {
43+
GTEST_SKIP() << "Device does supports setting program spec constants.";
44+
}
45+
}
46+
47+
uint32_t spec_value = 42;
48+
uint32_t default_spec_value = 1000; // Must match the one in the SYCL source
49+
ur_specialization_constant_info_t info = {0, sizeof(spec_value), &spec_value};
50+
};
51+
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(
52+
urProgramSetSpecializationConstantsNegativeTest);
53+
2254
struct urProgramSetMultipleSpecializationConstantsTest
2355
: uur::urKernelExecutionTest {
2456
// The types of spec constants in this program are {uint32_t, uint64_t, bool}
2557
void SetUp() override {
2658
program_name = "spec_constant_multiple";
2759
UUR_RETURN_ON_FATAL_FAILURE(urProgramTest::SetUp());
60+
61+
bool supports_kernel_spec_constant = false;
62+
ASSERT_SUCCESS(urDeviceGetInfo(
63+
device, UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS,
64+
sizeof(supports_kernel_spec_constant), &supports_kernel_spec_constant,
65+
nullptr));
66+
if (!supports_kernel_spec_constant) {
67+
GTEST_SKIP() << "Device does not support setting program spec constants.";
68+
}
2869
}
2970
};
3071
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(
3172
urProgramSetMultipleSpecializationConstantsTest);
3273

3374
TEST_P(urProgramSetSpecializationConstantsTest, Success) {
34-
UUR_KNOWN_FAILURE_ON(uur::CUDA{}, uur::HIP{});
35-
3675
ASSERT_SUCCESS(urProgramSetSpecializationConstants(program, 1, &info));
3776
ASSERT_SUCCESS(urProgramBuild(context, program, nullptr));
3877
auto entry_points =
@@ -46,9 +85,12 @@ TEST_P(urProgramSetSpecializationConstantsTest, Success) {
4685
ValidateBuffer<uint32_t>(buffer, sizeof(spec_value), spec_value);
4786
}
4887

49-
TEST_P(urProgramSetSpecializationConstantsTest, UseDefaultValue) {
50-
UUR_KNOWN_FAILURE_ON(uur::CUDA{}, uur::HIP{});
88+
TEST_P(urProgramSetSpecializationConstantsNegativeTest, Unsupported) {
89+
ASSERT_EQ_RESULT(UR_RESULT_ERROR_UNSUPPORTED_FEATURE,
90+
urProgramSetSpecializationConstants(program, 1, &info));
91+
}
5192

93+
TEST_P(urProgramSetSpecializationConstantsTest, UseDefaultValue) {
5294
ur_platform_backend_t backend;
5395
ASSERT_SUCCESS(urPlatformGetInfo(platform, UR_PLATFORM_INFO_BACKEND,
5496
sizeof(ur_platform_backend_t), &backend,
@@ -72,8 +114,6 @@ TEST_P(urProgramSetSpecializationConstantsTest, UseDefaultValue) {
72114
}
73115

74116
TEST_P(urProgramSetMultipleSpecializationConstantsTest, MultipleCalls) {
75-
UUR_KNOWN_FAILURE_ON(uur::CUDA{}, uur::HIP{});
76-
77117
uint32_t a = 100;
78118
uint64_t b = 200;
79119
bool c = false;
@@ -104,8 +144,6 @@ TEST_P(urProgramSetMultipleSpecializationConstantsTest, MultipleCalls) {
104144
}
105145

106146
TEST_P(urProgramSetMultipleSpecializationConstantsTest, SingleCall) {
107-
UUR_KNOWN_FAILURE_ON(uur::CUDA{}, uur::HIP{});
108-
109147
uint32_t a = 200;
110148
uint64_t b = 300;
111149
bool c = true;
@@ -159,8 +197,7 @@ TEST_P(urProgramSetSpecializationConstantsTest, InvalidValueSize) {
159197
}
160198

161199
TEST_P(urProgramSetSpecializationConstantsTest, InvalidValueId) {
162-
UUR_KNOWN_FAILURE_ON(uur::CUDA{}, uur::HIP{}, uur::LevelZero{},
163-
uur::LevelZeroV2{});
200+
UUR_KNOWN_FAILURE_ON(uur::LevelZero{}, uur::LevelZeroV2{});
164201

165202
ur_specialization_constant_info_t bad_info = {999, sizeof(spec_value),
166203
&spec_value};
@@ -169,8 +206,7 @@ TEST_P(urProgramSetSpecializationConstantsTest, InvalidValueId) {
169206
}
170207

171208
TEST_P(urProgramSetSpecializationConstantsTest, InvalidValuePtr) {
172-
UUR_KNOWN_FAILURE_ON(uur::CUDA{}, uur::HIP{}, uur::LevelZero{},
173-
uur::LevelZeroV2{});
209+
UUR_KNOWN_FAILURE_ON(uur::LevelZero{}, uur::LevelZeroV2{});
174210

175211
ur_specialization_constant_info_t bad_info = {0, sizeof(spec_value), nullptr};
176212
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_VALUE,

tools/urinfo/urinfo.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ inline void printDeviceInfos(ur_device_handle_t hDevice,
327327
std::cout << prefix;
328328
printDeviceInfo<ur_bool_t>(hDevice, UR_DEVICE_INFO_USM_POOL_SUPPORT);
329329
std::cout << prefix;
330+
printDeviceInfo<ur_bool_t>(
331+
hDevice, UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS);
332+
std::cout << prefix;
330333
printDeviceInfo<ur_bool_t>(hDevice,
331334
UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP);
332335
std::cout << prefix;

0 commit comments

Comments
 (0)