Skip to content

Commit ce3ac87

Browse files
committed
Remove ur_base_desc_t, use ur_base_properties_t instead.
The definitions of these two base structs are slightly different which potentially has weird consequences if a given pNext chain contains extension structs derived from both. Unifying these structs removes the possibility of their definitions drifting further apart and prevents the mixed pNext chain scenario.
1 parent 41228d3 commit ce3ac87

21 files changed

+92
-140
lines changed

include/ur.py

+25-33
Large diffs are not rendered by default.

include/ur_api.h

+26-34
Large diffs are not rendered by default.

scripts/core/CONTRIB.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,7 @@ The following naming conventions must be followed:
248248

249249
The following coding conventions must be followed:
250250

251-
* All descriptor structures must be derived from ${x}_base_desc_t
252-
* All property structures must be derived from ${x}_base_properties_t
251+
* All descriptor or property structures must be derived from ${x}_base_properties_t
253252
* All function input parameters must precede output parameters
254253
* All functions must return ${x}_result_t
255254

scripts/core/common.yml

-12
Original file line numberDiff line numberDiff line change
@@ -281,18 +281,6 @@ etors:
281281
type: struct
282282
desc: "Base for all properties types"
283283
name: $x_base_properties_t
284-
members:
285-
- type: $x_structure_type_t
286-
name: stype
287-
desc: "[in] type of this structure"
288-
- type: "void*"
289-
name: pNext
290-
desc: "[in,out][optional] pointer to extension-specific structure"
291-
init: nullptr
292-
--- #--------------------------------------------------------------------------
293-
type: struct
294-
desc: "Base for all descriptor types"
295-
name: $x_base_desc_t
296284
members:
297285
- type: $x_structure_type_t
298286
name: stype

scripts/core/device.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ value: "\"native_cpu\""
6969
type: struct
7070
desc: "Device Binary Type"
7171
name: $x_device_binary_t
72-
base: $x_base_desc_t
72+
base: $x_base_properties_t
7373
members:
7474
- type: const char*
7575
name: pDeviceTargetSpec

scripts/core/exp-bindless-images.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ etors:
135135
type: struct
136136
desc: "File descriptor"
137137
name: $x_exp_file_descriptor_t
138-
base: $x_base_desc_t
138+
base: $x_base_properties_t
139139
members:
140140
- type: int
141141
name: fd
@@ -144,7 +144,7 @@ members:
144144
type: struct
145145
desc: "Windows specific file handle"
146146
name: $x_exp_win32_handle_t
147-
base: $x_base_desc_t
147+
base: $x_base_properties_t
148148
members:
149149
- type: void*
150150
name: handle
@@ -176,14 +176,14 @@ type: struct
176176
desc: "Describes an interop memory resource descriptor"
177177
class: $xBindlessImages
178178
name: $x_exp_interop_mem_desc_t
179-
base: $x_base_desc_t
179+
base: $x_base_properties_t
180180
members: []
181181
--- #--------------------------------------------------------------------------
182182
type: struct
183183
desc: "Describes an interop semaphore resource descriptor"
184184
class: $xBindlessImages
185185
name: $x_exp_interop_semaphore_desc_t
186-
base: $x_base_desc_t
186+
base: $x_base_properties_t
187187
members: []
188188
--- #--------------------------------------------------------------------------
189189
type: function

scripts/core/exp-command-buffer.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ value: "\"$x_exp_command_buffer\""
5353
type: struct
5454
desc: "Command-Buffer Descriptor Type"
5555
name: $x_exp_command_buffer_desc_t
56-
base: $x_base_desc_t
56+
base: $x_base_properties_t
5757
members: []
5858
--- #--------------------------------------------------------------------------
5959
type: typedef

scripts/core/memory.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ type: struct
176176
desc: "Image descriptor type."
177177
class: $xMem
178178
name: $x_image_desc_t
179-
base: $x_base_desc_t
179+
base: $x_base_properties_t
180180
members:
181181
- type: $x_mem_type_t
182182
name: type
@@ -366,7 +366,7 @@ type: struct
366366
desc: "Buffer region type, used to describe a sub buffer"
367367
class: $xMem
368368
name: $x_buffer_region_t
369-
base: $x_base_desc_t
369+
base: $x_base_properties_t
370370
members:
371371
- type: size_t
372372
name: origin

scripts/core/queue.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ details:
213213
as part of a `pNext` chain.
214214
class: $xQueue
215215
name: $x_queue_native_desc_t
216-
base: $x_base_desc_t
216+
base: $x_base_properties_t
217217
members:
218218
- type: "void*"
219219
name: pNativeData

scripts/core/sampler.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ type: struct
6767
desc: "Sampler description."
6868
class: $xSampler
6969
name: $x_sampler_desc_t
70-
base: $x_base_desc_t
70+
base: $x_base_properties_t
7171
members:
7272
- type: bool
7373
name: normalizedCoords

scripts/core/usm.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ type: struct
136136
desc: "USM allocation descriptor type."
137137
class: $xUSM
138138
name: $x_usm_desc_t
139-
base: $x_base_desc_t
139+
base: $x_base_properties_t
140140
members:
141141
- type: $x_usm_advice_flags_t
142142
name: hints
@@ -155,7 +155,7 @@ details:
155155
as part of a `pNext` chain.
156156
class: $xUSM
157157
name: $x_usm_host_desc_t
158-
base: $x_base_desc_t
158+
base: $x_base_properties_t
159159
members:
160160
- type: $x_usm_host_mem_flags_t
161161
name: flags
@@ -168,7 +168,7 @@ details:
168168
as part of a `pNext` chain.
169169
class: $xUSM
170170
name: $x_usm_device_desc_t
171-
base: $x_base_desc_t
171+
base: $x_base_properties_t
172172
members:
173173
- type: $x_usm_device_mem_flags_t
174174
name: flags
@@ -178,7 +178,7 @@ type: struct
178178
desc: "USM pool descriptor type"
179179
class: $xUSM
180180
name: $x_usm_pool_desc_t
181-
base: $x_base_desc_t
181+
base: $x_base_properties_t
182182
members:
183183
- type: $x_usm_pool_flags_t
184184
name: flags
@@ -191,7 +191,7 @@ details:
191191
as part of a `pNext` chain.
192192
class: $xUSM
193193
name: $x_usm_pool_limits_desc_t
194-
base: $x_base_desc_t
194+
base: $x_base_properties_t
195195
members:
196196
- type: "size_t"
197197
name: maxPoolableSize

scripts/parse_specs.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -254,15 +254,12 @@ def __validate_etors(d, tags):
254254
def __validate_base(d):
255255
namespace = re.sub(r"(\$[a-z])\w+", r"\1", d['name'])
256256
valid_names = [
257-
"%s_base_desc_t"%namespace,
258257
"%s_base_properties_t"%namespace,
259258
"%s_driver_extension_properties_t"%namespace
260259
]
261260
if d['name'] not in valid_names:
262-
if type_traits.is_descriptor(d['name']) and not d.get('base', "").endswith("base_desc_t"):
263-
raise Exception("'base' must be '%s_base_desc_t': %s"%(namespace, d['name']))
264-
265-
elif type_traits.is_properties(d['name']) and not d.get('base', "").endswith("base_properties_t"):
261+
needs_base = type_traits.is_descriptor(d['name']) or type_traits.is_properties(d['name'])
262+
if needs_base and not d.get('base', "").endswith("base_properties_t"):
266263
raise Exception("'base' must be '%s_base_properties_t': %s"%(namespace, d['name']))
267264

268265
def __validate_members(d, tags):

source/adapters/cuda/image.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -850,8 +850,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesImportOpaqueFDExp(
850850

851851
void *pNext = const_cast<void *>(pInteropMemDesc->pNext);
852852
while (pNext != nullptr) {
853-
const ur_base_desc_t *BaseDesc =
854-
reinterpret_cast<const ur_base_desc_t *>(pNext);
853+
const auto *BaseDesc =
854+
reinterpret_cast<const ur_base_properties_t *>(pNext);
855855
if (BaseDesc->stype == UR_STRUCTURE_TYPE_EXP_FILE_DESCRIPTOR) {
856856
const ur_exp_file_descriptor_t *FileDescriptor =
857857
reinterpret_cast<const ur_exp_file_descriptor_t *>(pNext);
@@ -956,8 +956,8 @@ urBindlessImagesImportExternalSemaphoreOpaqueFDExp(
956956

957957
void *pNext = const_cast<void *>(pInteropSemaphoreDesc->pNext);
958958
while (pNext != nullptr) {
959-
const ur_base_desc_t *BaseDesc =
960-
reinterpret_cast<const ur_base_desc_t *>(pNext);
959+
const auto *BaseDesc =
960+
reinterpret_cast<const ur_base_properties_t *>(pNext);
961961
if (BaseDesc->stype == UR_STRUCTURE_TYPE_EXP_FILE_DESCRIPTOR) {
962962
const ur_exp_file_descriptor_t *FileDescriptor =
963963
reinterpret_cast<const ur_exp_file_descriptor_t *>(pNext);

source/adapters/cuda/sampler.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ urSamplerCreate(ur_context_handle_t hContext, const ur_sampler_desc_t *pDesc,
2929

3030
void *pNext = const_cast<void *>(pDesc->pNext);
3131
while (pNext != nullptr) {
32-
const ur_base_desc_t *BaseDesc =
33-
reinterpret_cast<const ur_base_desc_t *>(pNext);
32+
const auto *BaseDesc =
33+
reinterpret_cast<const ur_base_properties_t *>(pNext);
3434
if (BaseDesc->stype == UR_STRUCTURE_TYPE_EXP_SAMPLER_MIP_PROPERTIES) {
3535
const ur_exp_sampler_mip_properties_t *SamplerMipProperties =
3636
reinterpret_cast<const ur_exp_sampler_mip_properties_t *>(pNext);

source/adapters/cuda/usm.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context,
381381
: Context(Context) {
382382
const void *pNext = PoolDesc->pNext;
383383
while (pNext != nullptr) {
384-
const ur_base_desc_t *BaseDesc = static_cast<const ur_base_desc_t *>(pNext);
384+
const auto *BaseDesc = static_cast<const ur_base_properties_t *>(pNext);
385385
switch (BaseDesc->stype) {
386386
case UR_STRUCTURE_TYPE_USM_POOL_LIMITS_DESC: {
387387
const ur_usm_pool_limits_desc_t *Limits =

source/adapters/hip/usm.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context,
318318
: Context(Context) {
319319
const void *pNext = PoolDesc->pNext;
320320
while (pNext != nullptr) {
321-
const ur_base_desc_t *BaseDesc = static_cast<const ur_base_desc_t *>(pNext);
321+
const auto *BaseDesc = static_cast<const ur_base_properties_t *>(pNext);
322322
switch (BaseDesc->stype) {
323323
case UR_STRUCTURE_TYPE_USM_POOL_LIMITS_DESC: {
324324
const ur_usm_pool_limits_desc_t *Limits =

source/adapters/level_zero/queue.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueCreateWithNativeHandle(
571571

572572
if (NativeProperties) {
573573
OwnNativeHandle = NativeProperties->isNativeHandleOwned;
574-
void *pNext = NativeProperties->pNext;
574+
const void *pNext = NativeProperties->pNext;
575575
while (pNext) {
576576
const ur_base_properties_t *extendedProperties =
577577
reinterpret_cast<const ur_base_properties_t *>(pNext);

source/adapters/level_zero/usm.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMSharedAlloc(
442442

443443
void *pNext = USMDesc ? const_cast<void *>(USMDesc->pNext) : nullptr;
444444
while (pNext != nullptr) {
445-
const ur_base_desc_t *BaseDesc =
446-
reinterpret_cast<const ur_base_desc_t *>(pNext);
445+
const auto *BaseDesc =
446+
reinterpret_cast<const ur_base_properties_t *>(pNext);
447447
if (BaseDesc->stype == UR_STRUCTURE_TYPE_USM_DEVICE_DESC) {
448448
const ur_usm_device_desc_t *UsmDeviceDesc =
449449
reinterpret_cast<const ur_usm_device_desc_t *>(pNext);
@@ -751,8 +751,8 @@ ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context,
751751

752752
void *pNext = const_cast<void *>(PoolDesc->pNext);
753753
while (pNext != nullptr) {
754-
const ur_base_desc_t *BaseDesc =
755-
reinterpret_cast<const ur_base_desc_t *>(pNext);
754+
const auto *BaseDesc =
755+
reinterpret_cast<const ur_base_properties_t *>(pNext);
756756
switch (BaseDesc->stype) {
757757
case UR_STRUCTURE_TYPE_USM_POOL_LIMITS_DESC: {
758758
const ur_usm_pool_limits_desc_t *Limits =

source/adapters/opencl/memory.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -239,25 +239,27 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemBufferCreate(
239239
cl_ext::CreateBufferWithPropertiesName, &FuncPtr);
240240
if (FuncPtr) {
241241
std::vector<cl_mem_properties_intel> PropertiesIntel;
242-
auto Prop = static_cast<ur_base_properties_t *>(pProperties->pNext);
242+
const auto *Prop =
243+
static_cast<const ur_base_properties_t *>(pProperties->pNext);
243244
while (Prop) {
244245
switch (Prop->stype) {
245246
case UR_STRUCTURE_TYPE_BUFFER_CHANNEL_PROPERTIES: {
246247
auto BufferChannelProperty =
247-
reinterpret_cast<ur_buffer_channel_properties_t *>(Prop);
248+
reinterpret_cast<const ur_buffer_channel_properties_t *>(Prop);
248249
PropertiesIntel.push_back(CL_MEM_CHANNEL_INTEL);
249250
PropertiesIntel.push_back(BufferChannelProperty->channel);
250251
} break;
251252
case UR_STRUCTURE_TYPE_BUFFER_ALLOC_LOCATION_PROPERTIES: {
252253
auto BufferLocationProperty =
253-
reinterpret_cast<ur_buffer_alloc_location_properties_t *>(Prop);
254+
reinterpret_cast<const ur_buffer_alloc_location_properties_t *>(
255+
Prop);
254256
PropertiesIntel.push_back(CL_MEM_ALLOC_FLAGS_INTEL);
255257
PropertiesIntel.push_back(BufferLocationProperty->location);
256258
} break;
257259
default:
258260
break;
259261
}
260-
Prop = static_cast<ur_base_properties_t *>(Prop->pNext);
262+
Prop = static_cast<const ur_base_properties_t *>(Prop->pNext);
261263
}
262264
PropertiesIntel.push_back(0);
263265

source/adapters/opencl/usm.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ urUSMHostAlloc(ur_context_handle_t hContext, const ur_usm_desc_t *pUSMDesc,
2121
cl_mem_properties_intel Properties[3];
2222

2323
if (pUSMDesc && pUSMDesc->pNext &&
24-
static_cast<const ur_base_desc_t *>(pUSMDesc->pNext)->stype ==
24+
static_cast<const ur_base_properties_t *>(pUSMDesc->pNext)->stype ==
2525
UR_STRUCTURE_TYPE_USM_HOST_DESC) {
2626
const auto *HostDesc =
2727
static_cast<const ur_usm_host_desc_t *>(pUSMDesc->pNext);
@@ -74,7 +74,7 @@ urUSMDeviceAlloc(ur_context_handle_t hContext, ur_device_handle_t hDevice,
7474
cl_mem_alloc_flags_intel Flags = 0;
7575
cl_mem_properties_intel Properties[3];
7676
if (pUSMDesc && pUSMDesc->pNext &&
77-
static_cast<const ur_base_desc_t *>(pUSMDesc->pNext)->stype ==
77+
static_cast<const ur_base_properties_t *>(pUSMDesc->pNext)->stype ==
7878
UR_STRUCTURE_TYPE_USM_DEVICE_DESC) {
7979
const auto *HostDesc =
8080
static_cast<const ur_usm_device_desc_t *>(pUSMDesc->pNext);
@@ -131,7 +131,7 @@ urUSMSharedAlloc(ur_context_handle_t hContext, ur_device_handle_t hDevice,
131131

132132
cl_mem_alloc_flags_intel Flags = 0;
133133
const auto *NextStruct =
134-
(pUSMDesc ? static_cast<const ur_base_desc_t *>(pUSMDesc->pNext)
134+
(pUSMDesc ? static_cast<const ur_base_properties_t *>(pUSMDesc->pNext)
135135
: nullptr);
136136
while (NextStruct) {
137137
if (NextStruct->stype == UR_STRUCTURE_TYPE_USM_HOST_DESC) {
@@ -150,7 +150,7 @@ urUSMSharedAlloc(ur_context_handle_t hContext, ur_device_handle_t hDevice,
150150
Flags |= CL_MEM_ALLOC_WRITE_COMBINED_INTEL;
151151
}
152152
}
153-
NextStruct = static_cast<const ur_base_desc_t *>(NextStruct->pNext);
153+
NextStruct = static_cast<const ur_base_properties_t *>(NextStruct->pNext);
154154
}
155155

156156
cl_mem_properties_intel Properties[3] = {CL_MEM_ALLOC_FLAGS_INTEL, Flags, 0};

source/common/ur_params.hpp

-18
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,6 @@ inline std::ostream &operator<<(std::ostream &os,
226226
inline std::ostream &operator<<(std::ostream &os, enum ur_result_t value);
227227
inline std::ostream &operator<<(std::ostream &os,
228228
const struct ur_base_properties_t params);
229-
inline std::ostream &operator<<(std::ostream &os,
230-
const struct ur_base_desc_t params);
231229
inline std::ostream &operator<<(std::ostream &os,
232230
const struct ur_rect_offset_t params);
233231
inline std::ostream &operator<<(std::ostream &os,
@@ -1891,22 +1889,6 @@ inline std::ostream &operator<<(std::ostream &os,
18911889
os << "}";
18921890
return os;
18931891
}
1894-
inline std::ostream &operator<<(std::ostream &os,
1895-
const struct ur_base_desc_t params) {
1896-
os << "(struct ur_base_desc_t){";
1897-
1898-
os << ".stype = ";
1899-
1900-
os << (params.stype);
1901-
1902-
os << ", ";
1903-
os << ".pNext = ";
1904-
1905-
ur_params::serializeStruct(os, (params.pNext));
1906-
1907-
os << "}";
1908-
return os;
1909-
}
19101892
inline std::ostream &operator<<(std::ostream &os,
19111893
const struct ur_rect_offset_t params) {
19121894
os << "(struct ur_rect_offset_t){";

0 commit comments

Comments
 (0)