Skip to content

Commit b5dff26

Browse files
committed
Add validation for a few image_desc_t members.
Also removes these checks from the cuda and hip adapters since they should be caught by the validation layer now. The new validation rules bring image_desc_t in line with the CL struct it was derived from. We already had CTS coverage for them.
1 parent 04799e7 commit b5dff26

File tree

8 files changed

+38
-26
lines changed

8 files changed

+38
-26
lines changed

include/ur.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,8 +1248,8 @@ class ur_image_desc_t(Structure):
12481248
("arraySize", c_size_t), ## [in] image array size
12491249
("rowPitch", c_size_t), ## [in] image row pitch
12501250
("slicePitch", c_size_t), ## [in] image slice pitch
1251-
("numMipLevel", c_ulong), ## [in] number of MIP levels
1252-
("numSamples", c_ulong) ## [in] number of samples
1251+
("numMipLevel", c_ulong), ## [in] number of MIP levels, must be `0`
1252+
("numSamples", c_ulong) ## [in] number of samples, must be `0`
12531253
]
12541254

12551255
###############################################################################

include/ur_api.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2395,8 +2395,8 @@ typedef struct ur_image_desc_t {
23952395
size_t arraySize; ///< [in] image array size
23962396
size_t rowPitch; ///< [in] image row pitch
23972397
size_t slicePitch; ///< [in] image slice pitch
2398-
uint32_t numMipLevel; ///< [in] number of MIP levels
2399-
uint32_t numSamples; ///< [in] number of samples
2398+
uint32_t numMipLevel; ///< [in] number of MIP levels, must be `0`
2399+
uint32_t numSamples; ///< [in] number of samples, must be `0`
24002400

24012401
} ur_image_desc_t;
24022402

@@ -2424,6 +2424,10 @@ typedef struct ur_image_desc_t {
24242424
/// - ::UR_RESULT_ERROR_INVALID_VALUE
24252425
/// - ::UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR
24262426
/// + `pImageDesc && UR_MEM_TYPE_IMAGE1D_BUFFER < pImageDesc->type`
2427+
/// + `pImageDesc && pImageDesc->numMipLevel != 0`
2428+
/// + `pImageDesc && pImageDesc->numSamples != 0`
2429+
/// + `pImageDesc && pImageDesc->rowPitch != 0 && pHost == nullptr`
2430+
/// + `pImageDesc && pImageDesc->slicePitch != 0 && pHost == nullptr`
24272431
/// - ::UR_RESULT_ERROR_INVALID_IMAGE_SIZE
24282432
/// - ::UR_RESULT_ERROR_INVALID_OPERATION
24292433
/// - ::UR_RESULT_ERROR_INVALID_HOST_PTR

scripts/core/memory.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,10 @@ members:
201201
desc: "[in] image slice pitch"
202202
- type: uint32_t
203203
name: numMipLevel
204-
desc: "[in] number of MIP levels"
204+
desc: "[in] number of MIP levels, must be `0`"
205205
- type: uint32_t
206206
name: numSamples
207-
desc: "[in] number of samples"
207+
desc: "[in] number of samples, must be `0`"
208208
--- #--------------------------------------------------------------------------
209209
type: function
210210
desc: "Create an image object"
@@ -237,6 +237,10 @@ returns:
237237
- $X_RESULT_ERROR_INVALID_VALUE
238238
- $X_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR:
239239
- "`pImageDesc && UR_MEM_TYPE_IMAGE1D_BUFFER < pImageDesc->type`"
240+
- "`pImageDesc && pImageDesc->numMipLevel != 0`"
241+
- "`pImageDesc && pImageDesc->numSamples != 0`"
242+
- "`pImageDesc && pImageDesc->rowPitch != 0 && pHost == nullptr`"
243+
- "`pImageDesc && pImageDesc->slicePitch != 0 && pHost == nullptr`"
240244
- $X_RESULT_ERROR_INVALID_IMAGE_SIZE
241245
- $X_RESULT_ERROR_INVALID_OPERATION
242246
- $X_RESULT_ERROR_INVALID_HOST_PTR:

source/adapters/cuda/memory.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -231,16 +231,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemImageCreate(
231231
UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR);
232232
UR_ASSERT(pImageDesc->type <= UR_MEM_TYPE_IMAGE1D_BUFFER,
233233
UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR);
234-
UR_ASSERT(pImageDesc->numMipLevel == 0,
235-
UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR);
236-
UR_ASSERT(pImageDesc->numSamples == 0,
237-
UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR);
238-
if (!pHost) {
239-
UR_ASSERT(pImageDesc->rowPitch == 0,
240-
UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR);
241-
UR_ASSERT(pImageDesc->slicePitch == 0,
242-
UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR);
243-
}
244234

245235
ur_result_t Result = UR_RESULT_SUCCESS;
246236

source/adapters/hip/memory.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -373,16 +373,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemImageCreate(
373373
UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR);
374374
UR_ASSERT(pImageDesc->type <= UR_MEM_TYPE_IMAGE1D_BUFFER,
375375
UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR);
376-
UR_ASSERT(pImageDesc->numMipLevel == 0,
377-
UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR);
378-
UR_ASSERT(pImageDesc->numSamples == 0,
379-
UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR);
380-
if (!pHost) {
381-
UR_ASSERT(pImageDesc->rowPitch == 0,
382-
UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR);
383-
UR_ASSERT(pImageDesc->slicePitch == 0,
384-
UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR);
385-
}
386376

387377
ur_result_t Result = UR_RESULT_SUCCESS;
388378

source/loader/layers/validation/ur_valddi.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,22 @@ __urdlllocal ur_result_t UR_APICALL urMemImageCreate(
10391039
return UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR;
10401040
}
10411041

1042+
if (pImageDesc && pImageDesc->numMipLevel != 0) {
1043+
return UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR;
1044+
}
1045+
1046+
if (pImageDesc && pImageDesc->numSamples != 0) {
1047+
return UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR;
1048+
}
1049+
1050+
if (pImageDesc && pImageDesc->rowPitch != 0 && pHost == nullptr) {
1051+
return UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR;
1052+
}
1053+
1054+
if (pImageDesc && pImageDesc->slicePitch != 0 && pHost == nullptr) {
1055+
return UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR;
1056+
}
1057+
10421058
if (pHost == NULL &&
10431059
(flags & (UR_MEM_FLAG_USE_HOST_POINTER |
10441060
UR_MEM_FLAG_ALLOC_COPY_HOST_POINTER)) != 0) {

source/loader/ur_libapi.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,10 @@ ur_result_t UR_APICALL urContextSetExtendedDeleter(
14141414
/// - ::UR_RESULT_ERROR_INVALID_VALUE
14151415
/// - ::UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR
14161416
/// + `pImageDesc && UR_MEM_TYPE_IMAGE1D_BUFFER < pImageDesc->type`
1417+
/// + `pImageDesc && pImageDesc->numMipLevel != 0`
1418+
/// + `pImageDesc && pImageDesc->numSamples != 0`
1419+
/// + `pImageDesc && pImageDesc->rowPitch != 0 && pHost == nullptr`
1420+
/// + `pImageDesc && pImageDesc->slicePitch != 0 && pHost == nullptr`
14171421
/// - ::UR_RESULT_ERROR_INVALID_IMAGE_SIZE
14181422
/// - ::UR_RESULT_ERROR_INVALID_OPERATION
14191423
/// - ::UR_RESULT_ERROR_INVALID_HOST_PTR

source/ur_api.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,10 @@ ur_result_t UR_APICALL urContextSetExtendedDeleter(
12041204
/// - ::UR_RESULT_ERROR_INVALID_VALUE
12051205
/// - ::UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR
12061206
/// + `pImageDesc && UR_MEM_TYPE_IMAGE1D_BUFFER < pImageDesc->type`
1207+
/// + `pImageDesc && pImageDesc->numMipLevel != 0`
1208+
/// + `pImageDesc && pImageDesc->numSamples != 0`
1209+
/// + `pImageDesc && pImageDesc->rowPitch != 0 && pHost == nullptr`
1210+
/// + `pImageDesc && pImageDesc->slicePitch != 0 && pHost == nullptr`
12071211
/// - ::UR_RESULT_ERROR_INVALID_IMAGE_SIZE
12081212
/// - ::UR_RESULT_ERROR_INVALID_OPERATION
12091213
/// - ::UR_RESULT_ERROR_INVALID_HOST_PTR

0 commit comments

Comments
 (0)