Skip to content

Commit d2542ca

Browse files
committed
Default to legacy path
Signed-off-by: Neil R. Spruit <neil.r.spruit@intel.com>
1 parent 19d1221 commit d2542ca

22 files changed

Lines changed: 15450 additions & 10960 deletions

scripts/generate_code.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ def _mako_loader_cpp(path, namespace, tags, version, specs, meta):
151151
specs=specs,
152152
meta=meta)
153153

154-
template = "ldrddi_legacy.cpp.mako"
154+
template = "ldrddi_driver_ddi.cpp.mako"
155155
fin = os.path.join(templates_dir, template)
156156

157-
name = "%s_ldrddi_legacy"%(namespace)
157+
name = "%s_ldrddi_driver_ddi"%(namespace)
158158
filename = "%s.cpp"%(name)
159159
fout = os.path.join(path, filename)
160160

scripts/templates/helper.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,8 +1736,6 @@ def get_version(obj):
17361736
ret_version = "ZE_API_VERSION_1_11"
17371737
if version == "1.12":
17381738
ret_version = "ZE_API_VERSION_1_12"
1739-
if version == "1.13":
1740-
ret_version = "ZE_API_VERSION_1_13"
17411739
assert(ret_version != "ZE_API_VERSION_FORCE_UINT32")
17421740
return ret_version
17431741

scripts/templates/ldrddi.cpp.mako

Lines changed: 190 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ from templates import helper as th
1818
*/
1919
#include "${x}_loader_internal.h"
2020

21+
using namespace loader_driver_ddi;
22+
2123
namespace loader
2224
{
2325
%for obj in th.extract_objs(specs, r"function"):
@@ -179,7 +181,7 @@ namespace loader
179181
}
180182
drv.driverDDIHandleSupportQueried = true;
181183
}
182-
if (!(drv.properties.flags & ZE_DRIVER_DDI_HANDLE_EXT_FLAG_DDI_HANDLE_EXT_SUPPORTED)) {
184+
if (!(drv.properties.flags & ZE_DRIVER_DDI_HANDLE_EXT_FLAG_DDI_HANDLE_EXT_SUPPORTED) || !loader::context->driverDDIPathDefault) {
183185
${obj['params'][1]['name']}[ driver_index ] = reinterpret_cast<${n}_driver_handle_t>(
184186
context->${n}_driver_factory.getInstance( ${obj['params'][1]['name']}[ driver_index ], &drv.dditable ) );
185187
}
@@ -204,68 +206,207 @@ namespace loader
204206
%else:
205207
%for i, item in enumerate(th.get_loader_prologue(n, tags, obj, meta)):
206208
%if 0 == i:
207-
// extract handle's function pointer table
209+
// extract driver's function pointer table
208210
%if 'range' in item:
209-
%if namespace == "ze":
210-
auto dditable = reinterpret_cast<ze_handle_t*>( ${item['name']}[ 0 ] )->pCore;
211-
%elif namespace == "zet":
212-
auto dditable = reinterpret_cast<ze_handle_t*>( ${item['name']}[ 0 ] )->pTools;
213-
%elif namespace == "zes":
214-
auto dditable = reinterpret_cast<ze_handle_t*>( ${item['name']}[ 0 ] )->pSysman;
215-
%endif
211+
auto dditable = reinterpret_cast<${item['obj']}*>( ${item['name']}[ 0 ] )->dditable;
216212
%else:
217-
%if namespace == "ze":
218-
auto dditable = reinterpret_cast<ze_handle_t*>( ${item['name']} )->pCore;
219-
%elif namespace == "zet":
220-
auto dditable = reinterpret_cast<ze_handle_t*>( ${item['name']} )->pTools;
221-
%elif namespace == "zes":
222-
auto dditable = reinterpret_cast<ze_handle_t*>( ${item['name']} )->pSysman;
223-
%endif
213+
auto dditable = reinterpret_cast<${item['obj']}*>( ${item['name']} )->dditable;
224214
%endif
225-
if (dditable->isValidFlag == 0)
226-
return ${X}_RESULT_ERROR_UNINITIALIZED;
227-
// Check that api version in the driver is supported by this version of the API
228-
if (dditable->version < ${th.get_version(obj)}) {
229-
return ${X}_RESULT_ERROR_UNSUPPORTED_VERSION;
230-
}
231-
auto ${th.make_pfn_name(n, tags, obj)} = dditable->${th.get_table_name(n, tags, obj)}->${th.make_pfn_name(n, tags, obj)};
215+
auto ${th.make_pfn_name(n, tags, obj)} = dditable->${n}.${th.get_table_name(n, tags, obj)}.${th.make_pfn_name(n, tags, obj)};
232216
if( nullptr == ${th.make_pfn_name(n, tags, obj)} )
233217
return ${X}_RESULT_ERROR_UNINITIALIZED;
218+
219+
%endif
220+
%if 'range' in item:
221+
<%
222+
add_local = True%>// convert loader handles to driver handles
223+
auto ${item['name']}Local = new ${item['type']} [${item['range'][1]}];
224+
<%
225+
arrays_to_delete.append(item['name']+ 'Local')
226+
%>for( size_t i = ${item['range'][0]}; ( nullptr != ${item['name']} ) && ( i < ${item['range'][1]} ); ++i )
227+
${item['name']}Local[ i ] = reinterpret_cast<${item['obj']}*>( ${item['name']}[ i ] )->handle;
228+
%else:
229+
%if item['optional']:
230+
// convert loader handle to driver handle
231+
${item['name']} = ( ${item['name']} ) ? reinterpret_cast<${item['obj']}*>( ${item['name']} )->handle : nullptr;
232+
%else:
233+
%if re.match(r"\w+ImageDestroy$", th.make_func_name(n, tags, obj)):
234+
// remove the handle from the kernel arugment map
235+
{
236+
std::lock_guard<std::mutex> lock(context->image_handle_map_lock);
237+
context->image_handle_map.erase(reinterpret_cast<ze_image_object_t*>(hImage));
238+
}
234239
%endif
240+
%if re.match(r"\w+SamplerDestroy$", th.make_func_name(n, tags, obj)):
241+
// remove the handle from the kernel arugment map
242+
{
243+
std::lock_guard<std::mutex> lock(context->sampler_handle_map_lock);
244+
context->sampler_handle_map.erase(reinterpret_cast<ze_sampler_object_t*>(hSampler));
245+
}
246+
%endif
247+
// convert loader handle to driver handle
248+
${item['name']} = reinterpret_cast<${item['obj']}*>( ${item['name']} )->handle;
249+
%endif
250+
%endif
251+
235252
%endfor
253+
%if re.match(r"\w+KernelSetArgumentValue$", th.make_func_name(n, tags, obj)):
254+
// convert pArgValue to correct handle if applicable
255+
void *internalArgValue = const_cast<void *>(pArgValue);
256+
if (pArgValue) {
257+
// check if the arg value is a translated handle
258+
ze_image_object_t **imageHandle = static_cast<ze_image_object_t **>(internalArgValue);
259+
ze_sampler_object_t **samplerHandle = static_cast<ze_sampler_object_t **>(internalArgValue);
260+
{
261+
std::lock_guard<std::mutex> image_lock(context->image_handle_map_lock);
262+
std::lock_guard<std::mutex> sampler_lock(context->sampler_handle_map_lock);
263+
if( context->image_handle_map.find(*imageHandle) != context->image_handle_map.end() ) {
264+
internalArgValue = &context->image_handle_map[*imageHandle];
265+
} else if( context->sampler_handle_map.find(*samplerHandle) != context->sampler_handle_map.end() ) {
266+
internalArgValue = &context->sampler_handle_map[*samplerHandle];
267+
}
268+
}
269+
}
270+
%endif
271+
## Workaround due to incorrect defintion of phWaitEvents in the ze headers which missed the range values.
272+
## To be removed once the headers have been updated in a new spec release.
273+
%if re.match(r"\w+CommandListAppendMetricQueryEnd$", th.make_func_name(n, tags, obj)):
274+
// convert loader handles to driver handles
275+
auto phWaitEventsLocal = new ze_event_handle_t [numWaitEvents];
276+
for( size_t i = 0; ( nullptr != phWaitEvents ) && ( i < numWaitEvents ); ++i )
277+
phWaitEventsLocal[ i ] = reinterpret_cast<ze_event_object_t*>( phWaitEvents[ i ] )->handle;
278+
279+
// forward to device-driver
280+
result = pfnAppendMetricQueryEnd( hCommandList, hMetricQuery, hSignalEvent, numWaitEvents, phWaitEventsLocal );
281+
delete []phWaitEventsLocal;
282+
%else:
236283
// forward to device-driver
284+
%if add_local:
285+
result = ${th.make_pfn_name(n, tags, obj)}( ${", ".join(th.make_param_lines(n, tags, obj, format=["name", "local"]))} );
286+
%for array_name in arrays_to_delete:
287+
delete []${array_name};
288+
%endfor
289+
%else:
290+
%if re.match(r"\w+KernelSetArgumentValue$", th.make_func_name(n, tags, obj)):
291+
result = pfnSetArgumentValue( hKernel, argIndex, argSize, const_cast<const void *>(internalArgValue) );
292+
%else:
237293
result = ${th.make_pfn_name(n, tags, obj)}( ${", ".join(th.make_param_lines(n, tags, obj, format=["name"]))} );
294+
%endif
295+
%endif
296+
%endif
297+
<%
298+
del arrays_to_delete
299+
del add_local%>
300+
%for i, item in enumerate(th.get_loader_epilogue(n, tags, obj, meta)):
301+
%if 0 == i:
302+
%if not re.match(r"\w+ModuleDynamicLink$", th.make_func_name(n, tags, obj)) and not re.match(r"\w+ModuleCreate$", th.make_func_name(n, tags, obj)):
303+
if( ${X}_RESULT_SUCCESS != result )
304+
return result;
305+
306+
%endif
307+
%endif
308+
%if item['release']:
309+
// release loader handle
310+
context->${item['factory']}.release( ${item['name']} );
311+
%else:
312+
try
313+
{
314+
%if 'range' in item:
315+
// convert driver handles to loader handles
316+
for( size_t i = ${item['range'][0]}; ( nullptr != ${item['name']} ) && ( i < ${item['range'][1]} ); ++i )
317+
${item['name']}[ i ] = reinterpret_cast<${item['type']}>(
318+
context->${item['factory']}.getInstance( ${item['name']}[ i ], dditable ) );
319+
%else:
320+
// convert driver handle to loader handle
321+
%if item['optional']:
322+
if( nullptr != ${item['name']} )
323+
*${item['name']} = reinterpret_cast<${item['type']}>(
324+
context->${item['factory']}.getInstance( *${item['name']}, dditable ) );
325+
%else:
326+
%if re.match(r"\w+ImageCreate$", th.make_func_name(n, tags, obj)) or re.match(r"\w+SamplerCreate$", th.make_func_name(n, tags, obj)) or re.match(r"\w+ImageViewCreateExp$", th.make_func_name(n, tags, obj)):
327+
${item['type']} internalHandlePtr = *${item['name']};
328+
%endif
329+
*${item['name']} = reinterpret_cast<${item['type']}>(
330+
context->${item['factory']}.getInstance( *${item['name']}, dditable ) );
331+
%if re.match(r"\w+ImageCreate$", th.make_func_name(n, tags, obj)) or re.match(r"\w+ImageViewCreateExp$", th.make_func_name(n, tags, obj)):
332+
// convert loader handle to driver handle and store in map
333+
{
334+
std::lock_guard<std::mutex> lock(context->image_handle_map_lock);
335+
context->image_handle_map.insert({context->ze_image_factory.getInstance( internalHandlePtr, dditable ), internalHandlePtr});
336+
}
337+
%endif
338+
%if re.match(r"\w+SamplerCreate$", th.make_func_name(n, tags, obj)):
339+
// convert loader handle to driver handle and store in map
340+
{
341+
std::lock_guard<std::mutex> lock(context->sampler_handle_map_lock);
342+
context->sampler_handle_map.insert({context->ze_sampler_factory.getInstance( internalHandlePtr, dditable ), internalHandlePtr});
343+
}
344+
%endif
345+
%endif
346+
%endif
347+
}
348+
catch( std::bad_alloc& )
349+
{
350+
result = ${X}_RESULT_ERROR_OUT_OF_HOST_MEMORY;
351+
}
352+
%endif
353+
354+
%if 0 == i:
355+
%if re.match(r"\w+ModuleDynamicLink$", th.make_func_name(n, tags, obj)) or re.match(r"\w+ModuleCreate$", th.make_func_name(n, tags, obj)):
356+
if( ${X}_RESULT_SUCCESS != result )
357+
return result;
358+
359+
%endif
360+
%endif
361+
%endfor
362+
%endif
238363
return result;
239364
}
240365
%if 'condition' in obj:
241366
#endif // ${th.subt(n, tags, obj['condition'])}
242367
%endif
243368

244-
%endif
245-
%if re.match(r"Init", obj['name']) or re.match(r"\w+InitDrivers$", th.make_func_name(n, tags, obj)) or re.match(r"\w+DriverGet$", th.make_func_name(n, tags, obj)):
246-
return result;
247-
}
248-
%endif
249369
%endfor
250-
251-
///////////////////////////////////////////////////////////////////////////////
252-
/// @brief function for removing the ddi driver tables for ${n}
253-
__${x}dlllocal void ${X}_APICALL
254-
${n}DestroyDDiDriverTables(${n}_dditable_driver_t* pDdiTable)
255-
{
256-
// Delete ddi tables
257-
%for tbl in th.get_pfntables(specs, meta, n, tags):
258-
delete pDdiTable->${tbl['name']};
259-
%endfor
260-
delete pDdiTable;
261-
}
262-
263370
} // namespace loader
264371

265372
#if defined(__cplusplus)
266373
extern "C" {
267374
#endif
268375

376+
%for tbl in th.get_pfntables(specs, meta, n, tags):
377+
///////////////////////////////////////////////////////////////////////////////
378+
/// @brief function for filling the legacy api pointers for ${tbl['name']} table
379+
__${x}dlllocal void ${X}_APICALL
380+
${tbl['export']['name']}Legacy()
381+
{
382+
// return pointers to the Loader's Functions.
383+
%for obj in tbl['functions']:
384+
%if 'condition' in obj:
385+
#if ${th.subt(n, tags, obj['condition'])}
386+
%endif
387+
%if namespace == "ze":
388+
loader::loaderDispatch->pCore->${tbl['name']}->${th.append_ws(th.make_pfn_name(n, tags, obj), 43)} = loader::${th.make_func_name(n, tags, obj)};
389+
%elif namespace == "zet":
390+
loader::loaderDispatch->pTools->${tbl['name']}->${th.append_ws(th.make_pfn_name(n, tags, obj), 43)} = loader::${th.make_func_name(n, tags, obj)};
391+
%elif namespace == "zes":
392+
loader::loaderDispatch->pSysman->${tbl['name']}->${th.append_ws(th.make_pfn_name(n, tags, obj), 43)} = loader::${th.make_func_name(n, tags, obj)};
393+
%endif
394+
%if 'condition' in obj:
395+
#else
396+
%if namespace == "ze":
397+
loader::loaderDispatch->pCore->${tbl['name']}->${th.append_ws(th.make_pfn_name(n, tags, obj), 43)} = nullptr;
398+
%elif namespace == "zet":
399+
loader::loaderDispatch->pTools->${tbl['name']}->${th.append_ws(th.make_pfn_name(n, tags, obj), 43)} = nullptr;
400+
%elif namespace == "zes":
401+
loader::loaderDispatch->pSysman->${tbl['name']}->${th.append_ws(th.make_pfn_name(n, tags, obj), 43)} = nullptr;
402+
%endif
403+
#endif
404+
%endif
405+
%endfor
406+
}
407+
408+
%endfor
409+
269410
%for tbl in th.get_pfntables(specs, meta, n, tags):
270411
///////////////////////////////////////////////////////////////////////////////
271412
/// @brief Exported function for filling application's ${tbl['name']} table
@@ -368,7 +509,15 @@ ${tbl['export']['name']}(
368509
%if 'condition' in obj:
369510
#if ${th.subt(n, tags, obj['condition'])}
370511
%endif
512+
%if not (re.match(r"Init", obj['name']) or re.match(r"\w+InitDrivers$", th.make_func_name(n, tags, obj)) or re.match(r"\w+DriverGet$", th.make_func_name(n, tags, obj))):
513+
if (loader::context->driverDDIPathDefault) {
514+
pDdiTable->${th.append_ws(th.make_pfn_name(n, tags, obj), 43)} = loader_driver_ddi::${th.make_func_name(n, tags, obj)};
515+
} else {
516+
pDdiTable->${th.append_ws(th.make_pfn_name(n, tags, obj), 43)} = loader::${th.make_func_name(n, tags, obj)};
517+
}
518+
%else:
371519
pDdiTable->${th.append_ws(th.make_pfn_name(n, tags, obj), 43)} = loader::${th.make_func_name(n, tags, obj)};
520+
%endif
372521
%if 'condition' in obj:
373522
#else
374523
pDdiTable->${th.append_ws(th.make_pfn_name(n, tags, obj), 43)} = nullptr;

scripts/templates/ldrddi.h.mako

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,22 @@ namespace loader
3232

3333
%endif
3434
%endfor
35+
}
36+
37+
namespace loader_driver_ddi
38+
{
3539
__${x}dlllocal void ${X}_APICALL
3640
${n}DestroyDDiDriverTables(${n}_dditable_driver_t* pDdiTable);
41+
%for obj in th.extract_objs(specs, r"function"):
42+
%if not (re.match(r"Init", obj['name']) or re.match(r"\w+InitDrivers$", th.make_func_name(n, tags, obj)) or re.match(r"\w+DriverGet$", th.make_func_name(n, tags, obj))):
43+
__${x}dlllocal ${x}_result_t ${X}_APICALL
44+
${th.make_func_name(n, tags, obj)}(
45+
%for line in th.make_param_lines(n, tags, obj):
46+
${line}
47+
%endfor
48+
);
49+
%endif
50+
%endfor
3751
}
3852

3953
#if defined(__cplusplus)

0 commit comments

Comments
 (0)