Skip to content

Commit 38b0e8d

Browse files
authored
[UR] Improve handling for devices/platforms that don't support images (#20128)
Image support is optional and depends on UR_DEVICE_INFO_IMAGE_SUPPORT. Now, entrypoints that involve images should return UNSUPPORTED_FEATURE if image support is unavailable. The offload plugin now defines image functions as stubs that return this "UNSUPPORTED_FEATURE" value. CTS testing is more rebust. Support for images is now checked before trying to load the kernel binary, since that binary will not be available for platforms that don't support images.
1 parent 3b4b4b8 commit 38b0e8d

File tree

14 files changed

+182
-31
lines changed

14 files changed

+182
-31
lines changed

unified-runtime/include/ur_api.h

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unified-runtime/scripts/core/kernel.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,8 @@ params:
421421
desc: "[in] handle of Sampler object."
422422
returns:
423423
- $X_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_INDEX
424+
- $X_RESULT_ERROR_UNSUPPORTED_FEATURE:
425+
- "Device `$X_DEVICE_INFO_IMAGE_SUPPORT` is false"
424426
--- #--------------------------------------------------------------------------
425427
type: struct
426428
desc: "Properties for for $xKernelSetArgMemObj."

unified-runtime/scripts/core/memory.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ returns:
258258
- "`pImageDesc && pImageDesc->numSamples != 0`"
259259
- "`pImageDesc && pImageDesc->rowPitch != 0 && pHost == nullptr`"
260260
- "`pImageDesc && pImageDesc->slicePitch != 0 && pHost == nullptr`"
261+
- $X_RESULT_ERROR_UNSUPPORTED_FEATURE:
262+
- "Device `$X_DEVICE_INFO_IMAGE_SUPPORT` is false"
261263
- $X_RESULT_ERROR_INVALID_IMAGE_SIZE
262264
- $X_RESULT_ERROR_INVALID_OPERATION
263265
- $X_RESULT_ERROR_INVALID_HOST_PTR:
@@ -627,6 +629,8 @@ returns:
627629
- $X_RESULT_ERROR_INVALID_NULL_POINTER:
628630
- "`propSize != 0 && pPropValue == NULL`"
629631
- "`pPropValue == NULL && pPropSizeRet == NULL`"
632+
- $X_RESULT_ERROR_UNSUPPORTED_FEATURE:
633+
- "Device `$X_DEVICE_INFO_IMAGE_SUPPORT` is false"
630634
- $X_RESULT_ERROR_INVALID_MEM_OBJECT
631635
- $X_RESULT_ERROR_OUT_OF_RESOURCES
632636
- $X_RESULT_ERROR_OUT_OF_HOST_MEMORY

unified-runtime/scripts/core/sampler.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ returns:
105105
- $X_RESULT_ERROR_INVALID_OPERATION
106106
- $X_RESULT_ERROR_OUT_OF_HOST_MEMORY
107107
- $X_RESULT_ERROR_OUT_OF_RESOURCES
108+
- $X_RESULT_ERROR_UNSUPPORTED_FEATURE:
109+
- "Device `$X_DEVICE_INFO_IMAGE_SUPPORT` is false"
108110
--- #--------------------------------------------------------------------------
109111
type: function
110112
desc: "Get a reference to the sampler object handle. Increment its reference count"
@@ -121,6 +123,8 @@ returns:
121123
- $X_RESULT_ERROR_INVALID_SAMPLER
122124
- $X_RESULT_ERROR_OUT_OF_HOST_MEMORY
123125
- $X_RESULT_ERROR_OUT_OF_RESOURCES
126+
- $X_RESULT_ERROR_UNSUPPORTED_FEATURE:
127+
- "Device `$X_DEVICE_INFO_IMAGE_SUPPORT` is false"
124128
--- #--------------------------------------------------------------------------
125129
type: function
126130
desc: "Decrement the sampler's reference count and delete the sampler if the reference count becomes zero."
@@ -137,6 +141,8 @@ returns:
137141
- $X_RESULT_ERROR_INVALID_SAMPLER
138142
- $X_RESULT_ERROR_OUT_OF_HOST_MEMORY
139143
- $X_RESULT_ERROR_OUT_OF_RESOURCES
144+
- $X_RESULT_ERROR_UNSUPPORTED_FEATURE:
145+
- "Device `$X_DEVICE_INFO_IMAGE_SUPPORT` is false"
140146
--- #--------------------------------------------------------------------------
141147
type: function
142148
desc: "Query information about a sampler object"
@@ -173,6 +179,8 @@ returns:
173179
- $X_RESULT_ERROR_INVALID_SAMPLER
174180
- $X_RESULT_ERROR_OUT_OF_HOST_MEMORY
175181
- $X_RESULT_ERROR_OUT_OF_RESOURCES
182+
- $X_RESULT_ERROR_UNSUPPORTED_FEATURE:
183+
- "Device `$X_DEVICE_INFO_IMAGE_SUPPORT` is false"
176184
--- #--------------------------------------------------------------------------
177185
type: function
178186
desc: "Return sampler native sampler handle."

unified-runtime/source/adapters/offload/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ add_ur_adapter(${TARGET_NAME}
1717
${CMAKE_CURRENT_SOURCE_DIR}/platform.cpp
1818
${CMAKE_CURRENT_SOURCE_DIR}/program.cpp
1919
${CMAKE_CURRENT_SOURCE_DIR}/queue.cpp
20+
${CMAKE_CURRENT_SOURCE_DIR}/sampler.cpp
2021
${CMAKE_CURRENT_SOURCE_DIR}/ur2offload.hpp
2122
${CMAKE_CURRENT_SOURCE_DIR}/ur_interface_loader.cpp
2223
${CMAKE_CURRENT_SOURCE_DIR}/usm.cpp

unified-runtime/source/adapters/offload/kernel.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelGetSuggestedLocalWorkSize(
160160
const size_t *, size_t *) {
161161
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
162162
}
163+
164+
UR_APIEXPORT ur_result_t UR_APICALL urKernelSetArgSampler(
165+
ur_kernel_handle_t, uint32_t, const ur_kernel_arg_sampler_properties_t *,
166+
ur_sampler_handle_t) {
167+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
168+
}

unified-runtime/source/adapters/offload/memory.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,22 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemBufferPartition(
142142

143143
return urMemRetain(hBuffer);
144144
}
145+
146+
UR_APIEXPORT ur_result_t UR_APICALL
147+
urMemImageCreate(ur_context_handle_t, ur_mem_flags_t, const ur_image_format_t *,
148+
const ur_image_desc_t *, void *, ur_mem_handle_t *) {
149+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
150+
}
151+
152+
UR_APIEXPORT ur_result_t UR_APICALL urMemImageCreateWithNativeHandle(
153+
ur_native_handle_t, ur_context_handle_t, const ur_image_format_t *,
154+
const ur_image_desc_t *, const ur_mem_native_properties_t *,
155+
ur_mem_handle_t *) {
156+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
157+
}
158+
159+
UR_APIEXPORT ur_result_t UR_APICALL urMemImageGetInfo(ur_mem_handle_t,
160+
ur_image_info_t, size_t,
161+
void *, size_t *) {
162+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
163+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//===--------- sampler.cpp - LLVM Offload Adapter -------------------------===//
2+
//
3+
// Copyright (C) 2023 Intel Corporation
4+
//
5+
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
6+
// Exceptions. See LICENSE.TXT
7+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8+
//
9+
//===----------------------------------------------------------------------===//
10+
11+
#include "ur_api.h"
12+
13+
UR_APIEXPORT ur_result_t UR_APICALL urSamplerCreate(
14+
ur_context_handle_t /*hContext*/, const ur_sampler_desc_t * /*pDesc*/,
15+
ur_sampler_handle_t * /*phSampler*/) {
16+
17+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
18+
}
19+
20+
UR_APIEXPORT ur_result_t UR_APICALL
21+
urSamplerRetain(ur_sampler_handle_t /*hSampler*/) {
22+
23+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
24+
}
25+
26+
UR_APIEXPORT ur_result_t UR_APICALL
27+
urSamplerRelease(ur_sampler_handle_t /*hSampler*/) {
28+
29+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
30+
}
31+
32+
UR_APIEXPORT ur_result_t UR_APICALL urSamplerGetInfo(
33+
ur_sampler_handle_t /*hSampler*/, ur_sampler_info_t /*propName*/,
34+
size_t /*propSize*/, void * /*pPropValue*/, size_t * /*pPropSizeRet*/) {
35+
36+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
37+
}
38+
39+
UR_APIEXPORT ur_result_t UR_APICALL
40+
urSamplerGetNativeHandle(ur_sampler_handle_t /*hSampler*/,
41+
ur_native_handle_t * /*phNativeSampler*/) {
42+
43+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
44+
}
45+
46+
UR_APIEXPORT ur_result_t UR_APICALL urSamplerCreateWithNativeHandle(
47+
ur_native_handle_t /*hNativeSampler*/, ur_context_handle_t /*hContext*/,
48+
const ur_sampler_native_properties_t * /*pProperties*/,
49+
ur_sampler_handle_t * /*phSampler*/) {
50+
51+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
52+
}

unified-runtime/source/adapters/offload/ur_interface_loader.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetKernelProcAddrTable(
120120
pDdiTable->pfnSetArgLocal = nullptr;
121121
pDdiTable->pfnSetArgMemObj = urKernelSetArgMemObj;
122122
pDdiTable->pfnSetArgPointer = urKernelSetArgPointer;
123-
pDdiTable->pfnSetArgSampler = nullptr;
123+
pDdiTable->pfnSetArgSampler = urKernelSetArgSampler;
124124
pDdiTable->pfnSetArgValue = urKernelSetArgValue;
125125
pDdiTable->pfnSetExecInfo = urKernelSetExecInfo;
126126
pDdiTable->pfnSetSpecializationConstants = urKernelSetSpecializationConstants;
@@ -134,12 +134,12 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetSamplerProcAddrTable(
134134
if (UR_RESULT_SUCCESS != result) {
135135
return result;
136136
}
137-
pDdiTable->pfnCreate = nullptr;
138-
pDdiTable->pfnCreateWithNativeHandle = nullptr;
139-
pDdiTable->pfnGetInfo = nullptr;
140-
pDdiTable->pfnGetNativeHandle = nullptr;
141-
pDdiTable->pfnRelease = nullptr;
142-
pDdiTable->pfnRetain = nullptr;
137+
pDdiTable->pfnCreate = urSamplerCreate;
138+
pDdiTable->pfnCreateWithNativeHandle = urSamplerCreateWithNativeHandle;
139+
pDdiTable->pfnGetInfo = urSamplerGetInfo;
140+
pDdiTable->pfnGetNativeHandle = urSamplerGetNativeHandle;
141+
pDdiTable->pfnRelease = urSamplerRelease;
142+
pDdiTable->pfnRetain = urSamplerRetain;
143143
return UR_RESULT_SUCCESS;
144144
}
145145

@@ -152,11 +152,11 @@ urGetMemProcAddrTable(ur_api_version_t version, ur_mem_dditable_t *pDdiTable) {
152152
pDdiTable->pfnBufferCreate = urMemBufferCreate;
153153
pDdiTable->pfnBufferPartition = urMemBufferPartition;
154154
pDdiTable->pfnBufferCreateWithNativeHandle = nullptr;
155-
pDdiTable->pfnImageCreateWithNativeHandle = nullptr;
155+
pDdiTable->pfnImageCreateWithNativeHandle = urMemImageCreateWithNativeHandle;
156156
pDdiTable->pfnGetInfo = urMemGetInfo;
157157
pDdiTable->pfnGetNativeHandle = nullptr;
158-
pDdiTable->pfnImageCreate = nullptr;
159-
pDdiTable->pfnImageGetInfo = nullptr;
158+
pDdiTable->pfnImageCreate = urMemImageCreate;
159+
pDdiTable->pfnImageGetInfo = urMemImageGetInfo;
160160
pDdiTable->pfnRelease = urMemRelease;
161161
pDdiTable->pfnRetain = urMemRetain;
162162
return UR_RESULT_SUCCESS;

unified-runtime/source/loader/ur_libapi.cpp

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)