Skip to content

Commit 08d36b7

Browse files
authored
Merge pull request intel#2614 from kurapov-peter/spills
Add UR_KERNEL_INFO_SPILL_MEM_SIZE kernel info prop
2 parents 4c504db + e6b61c6 commit 08d36b7

File tree

14 files changed

+77
-4
lines changed

14 files changed

+77
-4
lines changed

include/ur_api.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5993,6 +5993,13 @@ typedef enum ur_kernel_info_t {
59935993
/// [uint32_t][optional-query] Return the number of registers used by the
59945994
/// compiled kernel.
59955995
UR_KERNEL_INFO_NUM_REGS = 6,
5996+
/// [uint32_t[]][optional-query] Return the spill memory size allocated by
5997+
/// the compiler.
5998+
/// The returned values correspond to the associated devices.
5999+
/// The order of the devices is guaranteed (i.e., the same as queried by
6000+
/// `urDeviceGet`) by the UR within a single application even if the runtime
6001+
/// is reinitialized.
6002+
UR_KERNEL_INFO_SPILL_MEM_SIZE = 7,
59966003
/// @cond
59976004
UR_KERNEL_INFO_FORCE_UINT32 = 0x7fffffff
59986005
/// @endcond
@@ -6093,7 +6100,7 @@ typedef enum ur_kernel_exec_info_t {
60936100
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
60946101
/// + `NULL == hKernel`
60956102
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
6096-
/// + `::UR_KERNEL_INFO_NUM_REGS < propName`
6103+
/// + `::UR_KERNEL_INFO_SPILL_MEM_SIZE < propName`
60976104
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
60986105
/// + If `propName` is not supported by the adapter.
60996106
/// - ::UR_RESULT_ERROR_INVALID_SIZE

include/ur_print.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8781,6 +8781,9 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_kernel_info_t value) {
87818781
case UR_KERNEL_INFO_NUM_REGS:
87828782
os << "UR_KERNEL_INFO_NUM_REGS";
87838783
break;
8784+
case UR_KERNEL_INFO_SPILL_MEM_SIZE:
8785+
os << "UR_KERNEL_INFO_SPILL_MEM_SIZE";
8786+
break;
87848787
default:
87858788
os << "unknown enumerator";
87868789
break;
@@ -8873,6 +8876,20 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr,
88738876

88748877
os << ")";
88758878
} break;
8879+
case UR_KERNEL_INFO_SPILL_MEM_SIZE: {
8880+
8881+
const uint32_t *tptr = (const uint32_t *)ptr;
8882+
os << "{";
8883+
size_t nelems = size / sizeof(uint32_t);
8884+
for (size_t i = 0; i < nelems; ++i) {
8885+
if (i != 0) {
8886+
os << ", ";
8887+
}
8888+
8889+
os << tptr[i];
8890+
}
8891+
os << "}";
8892+
} break;
88768893
default:
88778894
os << "unknown enumerator";
88788895
return UR_RESULT_ERROR_INVALID_ENUMERATION;

scripts/core/kernel.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ etors:
125125
desc: "[char[]] Return null-terminated kernel attributes string."
126126
- name: NUM_REGS
127127
desc: "[uint32_t][optional-query] Return the number of registers used by the compiled kernel."
128+
- name: SPILL_MEM_SIZE
129+
desc: |
130+
[uint32_t[]][optional-query] Return the spill memory size allocated by the compiler.
131+
The returned values correspond to the associated devices.
132+
The order of the devices is guaranteed (i.e., the same as queried by `urDeviceGet`)
133+
by the UR within a single application even if the runtime is reinitialized.
128134
--- #--------------------------------------------------------------------------
129135
type: enum
130136
desc: "Get Kernel Work Group information"

source/adapters/cuda/kernel.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelGetInfo(ur_kernel_handle_t hKernel,
299299
hKernel->get()));
300300
return ReturnValue(static_cast<uint32_t>(NumRegs));
301301
}
302+
case UR_KERNEL_INFO_SPILL_MEM_SIZE:
303+
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
302304
default:
303305
break;
304306
}

source/adapters/hip/kernel.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelGetInfo(ur_kernel_handle_t hKernel,
234234
hKernel->get()));
235235
return ReturnValue(static_cast<uint32_t>(NumRegs));
236236
}
237+
case UR_KERNEL_INFO_SPILL_MEM_SIZE:
238+
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
237239
default:
238240
break;
239241
}

source/adapters/level_zero/kernel.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,12 @@ ur_result_t urKernelGetInfo(
751751
case UR_KERNEL_INFO_NUM_REGS:
752752
case UR_KERNEL_INFO_NUM_ARGS:
753753
return ReturnValue(uint32_t{Kernel->ZeKernelProperties->numKernelArgs});
754+
case UR_KERNEL_INFO_SPILL_MEM_SIZE: {
755+
std::vector<uint32_t> spills = {
756+
uint32_t{Kernel->ZeKernelProperties->spillMemSize}};
757+
return ReturnValue(static_cast<const uint32_t *>(spills.data()),
758+
spills.size());
759+
}
754760
case UR_KERNEL_INFO_REFERENCE_COUNT:
755761
return ReturnValue(uint32_t{Kernel->RefCount.load()});
756762
case UR_KERNEL_INFO_ATTRIBUTES:

source/adapters/level_zero/v2/kernel.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,16 @@ ur_result_t urKernelGetInfo(ur_kernel_handle_t hKernel,
625625
case UR_KERNEL_INFO_NUM_REGS:
626626
case UR_KERNEL_INFO_NUM_ARGS:
627627
return ReturnValue(uint32_t{hKernel->getCommonProperties().numKernelArgs});
628+
case UR_KERNEL_INFO_SPILL_MEM_SIZE: {
629+
std::shared_lock<ur_shared_mutex> Guard(hKernel->getProgramHandle()->Mutex);
630+
auto devices = hKernel->getProgramHandle()->AssociatedDevices;
631+
std::vector<uint32_t> spills(devices.size());
632+
for (size_t i = 0; i < spills.size(); ++i) {
633+
spills[i] = uint32_t{hKernel->getProperties(devices[i]).spillMemSize};
634+
}
635+
return ReturnValue(static_cast<const uint32_t *>(spills.data()),
636+
spills.size());
637+
}
628638
case UR_KERNEL_INFO_REFERENCE_COUNT:
629639
return ReturnValue(uint32_t{hKernel->RefCount.load()});
630640
case UR_KERNEL_INFO_ATTRIBUTES: {

source/adapters/native_cpu/kernel.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelGetInfo(ur_kernel_handle_t hKernel,
105105
return ReturnValue(uint32_t{hKernel->getReferenceCount()});
106106
case UR_KERNEL_INFO_ATTRIBUTES:
107107
return ReturnValue("");
108+
case UR_KERNEL_INFO_SPILL_MEM_SIZE:
109+
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
108110
default:
109111
return UR_RESULT_ERROR_INVALID_VALUE;
110112
}

source/adapters/opencl/kernel.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ static cl_int mapURKernelInfoToCL(ur_kernel_info_t URPropName) {
6464
return CL_KERNEL_ATTRIBUTES;
6565
// NUM_REGS doesn't have a CL equivalent
6666
case UR_KERNEL_INFO_NUM_REGS:
67+
case UR_KERNEL_INFO_SPILL_MEM_SIZE:
6768
default:
6869
return -1;
6970
}
@@ -78,6 +79,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelGetInfo(ur_kernel_handle_t hKernel,
7879
if (propName == UR_KERNEL_INFO_NUM_REGS) {
7980
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
8081
}
82+
if (propName == UR_KERNEL_INFO_SPILL_MEM_SIZE) {
83+
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
84+
}
8185
size_t CheckPropSize = 0;
8286
cl_int ClResult = clGetKernelInfo(cl_adapter::cast<cl_kernel>(hKernel),
8387
mapURKernelInfoToCL(propName), propSize,

source/loader/layers/validation/ur_valddi.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3315,7 +3315,7 @@ __urdlllocal ur_result_t UR_APICALL urKernelGetInfo(
33153315
if (pPropValue == NULL && pPropSizeRet == NULL)
33163316
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
33173317

3318-
if (UR_KERNEL_INFO_NUM_REGS < propName)
3318+
if (UR_KERNEL_INFO_SPILL_MEM_SIZE < propName)
33193319
return UR_RESULT_ERROR_INVALID_ENUMERATION;
33203320

33213321
if (propSize == 0 && pPropValue != NULL)

source/loader/ur_libapi.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3798,7 +3798,7 @@ ur_result_t UR_APICALL urKernelSetArgLocal(
37983798
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
37993799
/// + `NULL == hKernel`
38003800
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
3801-
/// + `::UR_KERNEL_INFO_NUM_REGS < propName`
3801+
/// + `::UR_KERNEL_INFO_SPILL_MEM_SIZE < propName`
38023802
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
38033803
/// + If `propName` is not supported by the adapter.
38043804
/// - ::UR_RESULT_ERROR_INVALID_SIZE

source/ur_api.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3330,7 +3330,7 @@ ur_result_t UR_APICALL urKernelSetArgLocal(
33303330
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
33313331
/// + `NULL == hKernel`
33323332
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
3333-
/// + `::UR_KERNEL_INFO_NUM_REGS < propName`
3333+
/// + `::UR_KERNEL_INFO_SPILL_MEM_SIZE < propName`
33343334
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
33353335
/// + If `propName` is not supported by the adapter.
33363336
/// - ::UR_RESULT_ERROR_INVALID_SIZE

test/conformance/kernel/urKernelGetInfo.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,22 @@ TEST_P(urKernelGetInfoTest, SuccessNumRegs) {
136136
property_value.data(), nullptr));
137137
}
138138

139+
TEST_P(urKernelGetInfoTest, SuccessSpillMemSize) {
140+
UUR_KNOWN_FAILURE_ON(uur::HIP{}, uur::OpenCL{});
141+
142+
ur_kernel_info_t property_name = UR_KERNEL_INFO_SPILL_MEM_SIZE;
143+
size_t property_size = 0;
144+
145+
ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
146+
urKernelGetInfo(kernel, property_name, 0, nullptr, &property_size),
147+
property_name);
148+
ASSERT_EQ(property_size, sizeof(uint32_t));
149+
150+
std::vector<uint32_t> property_value(property_size / sizeof(uint32_t));
151+
ASSERT_SUCCESS(urKernelGetInfo(kernel, property_name, property_size,
152+
property_value.data(), nullptr));
153+
}
154+
139155
TEST_P(urKernelGetInfoTest, InvalidNullHandleKernel) {
140156
size_t kernel_name_length = 0;
141157
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,

test/conformance/testing/include/uur/optional_queries.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ template <> inline bool isQueryOptional(ur_program_info_t query) {
8686

8787
constexpr std::array optional_ur_kernel_info_t = {
8888
UR_KERNEL_INFO_NUM_REGS,
89+
UR_KERNEL_INFO_SPILL_MEM_SIZE,
8990
};
9091

9192
template <> inline bool isQueryOptional(ur_kernel_info_t query) {

0 commit comments

Comments
 (0)