Skip to content

Commit b4293e1

Browse files
committed
Add support for handling old and new handles used in handle translation
Signed-off-by: Neil R. Spruit <neil.r.spruit@intel.com>
1 parent 7f2769f commit b4293e1

5 files changed

Lines changed: 1463 additions & 24 deletions

File tree

source/drivers/null/ze_null.cpp

Lines changed: 233 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ namespace driver
6868
{
6969
auto pNext = reinterpret_cast<ze_base_properties_t *>(pDriverProperties->pNext);
7070
while (pNext) {
71-
if (pNext->stype == ZE_STRUCTURE_TYPE_DRIVER_DDI_HANDLES_EXT_PROPERTIES) {
71+
auto ddi_test_disable = getenv_string( "ZEL_TEST_NULL_DRIVER_DISABLE_DDI_EXT" );
72+
if (pNext->stype == ZE_STRUCTURE_TYPE_DRIVER_DDI_HANDLES_EXT_PROPERTIES && ddi_test_disable != "1") {
7273
ze_driver_ddi_handles_ext_properties_t *pDdiHandlesExtProperties = reinterpret_cast<ze_driver_ddi_handles_ext_properties_t *>(pNext);
7374
pDdiHandlesExtProperties->flags = ze_driver_ddi_handle_ext_flag_t::ZE_DRIVER_DDI_HANDLE_EXT_FLAG_DDI_HANDLE_EXT_SUPPORTED;
7475
context.ddiExtensionRequested = true;
@@ -79,8 +80,6 @@ namespace driver
7980

8081
return ZE_RESULT_SUCCESS;
8182
};
82-
83-
//pfnGetIPCProperties
8483

8584
//////////////////////////////////////////////////////////////////////////
8685
zeDdiTable.Mem.pfnAllocShared = [](
@@ -130,14 +129,227 @@ namespace driver
130129
return ZE_RESULT_SUCCESS;
131130
};
132131

133-
//pfnGetMemProperties
134-
//pfnGetMemAddressRange
135-
//pfnGetMemIpcHandle
136-
//pfnOpenMemIpcHandle
137-
//pfnCloseMemIpcHandle
132+
//////////////////////////////////////////////////////////////////////////
133+
zeDdiTable.EventPool.pfnCreate = [](
134+
ze_context_handle_t,
135+
const ze_event_pool_desc_t* desc,
136+
uint32_t,
137+
ze_device_handle_t*,
138+
ze_event_pool_handle_t* phEventPool )
139+
{
140+
*phEventPool = reinterpret_cast<ze_event_pool_handle_t>(context.get());
141+
return ZE_RESULT_SUCCESS;
142+
};
143+
144+
//////////////////////////////////////////////////////////////////////////
145+
zeDdiTable.Event.pfnCreate = [](
146+
ze_event_pool_handle_t,
147+
const ze_event_desc_t* desc,
148+
ze_event_handle_t* phEvent )
149+
{
150+
*phEvent = reinterpret_cast<ze_event_handle_t>(context.get());
151+
return ZE_RESULT_SUCCESS;
152+
};
153+
154+
//////////////////////////////////////////////////////////////////////////
155+
zeDdiTable.CommandList.pfnCreate = [](
156+
ze_context_handle_t,
157+
ze_device_handle_t,
158+
const ze_command_list_desc_t* desc,
159+
ze_command_list_handle_t* phCommandList )
160+
{
161+
*phCommandList = reinterpret_cast<ze_command_list_handle_t>(context.get());
162+
return ZE_RESULT_SUCCESS;
163+
};
164+
165+
//////////////////////////////////////////////////////////////////////////
166+
zeDdiTable.CommandQueue.pfnCreate = [](
167+
ze_context_handle_t,
168+
ze_device_handle_t,
169+
const ze_command_queue_desc_t* desc,
170+
ze_command_queue_handle_t* phCommandQueue )
171+
{
172+
*phCommandQueue = reinterpret_cast<ze_command_queue_handle_t>(context.get());
173+
return ZE_RESULT_SUCCESS;
174+
};
138175

139176
//////////////////////////////////////////////////////////////////////////
140-
//pfnGetSubDevices
177+
zeDdiTable.Context.pfnCreate = [](
178+
ze_driver_handle_t,
179+
const ze_context_desc_t*,
180+
ze_context_handle_t* phContext )
181+
{
182+
*phContext = reinterpret_cast<ze_context_handle_t>(context.get());
183+
return ZE_RESULT_SUCCESS;
184+
};
185+
186+
//////////////////////////////////////////////////////////////////////////
187+
zeDdiTable.Context.pfnDestroy = [](
188+
ze_context_handle_t )
189+
{
190+
return ZE_RESULT_SUCCESS;
191+
};
192+
193+
//////////////////////////////////////////////////////////////////////////
194+
zeDdiTable.CommandList.pfnDestroy = [](
195+
ze_command_list_handle_t )
196+
{
197+
return ZE_RESULT_SUCCESS;
198+
};
199+
200+
//////////////////////////////////////////////////////////////////////////
201+
zeDdiTable.CommandQueue.pfnDestroy = [](
202+
ze_command_queue_handle_t )
203+
{
204+
return ZE_RESULT_SUCCESS;
205+
};
206+
207+
//////////////////////////////////////////////////////////////////////////
208+
zeDdiTable.EventPool.pfnDestroy = [](
209+
ze_event_pool_handle_t )
210+
{
211+
return ZE_RESULT_SUCCESS;
212+
};
213+
214+
//////////////////////////////////////////////////////////////////////////
215+
zeDdiTable.Event.pfnDestroy = [](
216+
ze_event_handle_t )
217+
{
218+
return ZE_RESULT_SUCCESS;
219+
};
220+
//////////////////////////////////////////////////////////////////////////
221+
zeDdiTable.Module.pfnCreate = [](
222+
ze_context_handle_t,
223+
ze_device_handle_t,
224+
const ze_module_desc_t*,
225+
ze_module_handle_t* phModule,
226+
ze_module_build_log_handle_t* phModuleBuildLog )
227+
{
228+
*phModule = reinterpret_cast<ze_module_handle_t>(context.get());
229+
if (phModuleBuildLog) {
230+
*phModuleBuildLog = reinterpret_cast<ze_module_build_log_handle_t>(context.get());
231+
}
232+
return ZE_RESULT_SUCCESS;
233+
};
234+
235+
//////////////////////////////////////////////////////////////////////////
236+
zeDdiTable.Module.pfnDestroy = [](
237+
ze_module_handle_t )
238+
{
239+
return ZE_RESULT_SUCCESS;
240+
};
241+
242+
//////////////////////////////////////////////////////////////////////////
243+
zeDdiTable.ModuleBuildLog.pfnDestroy = [](
244+
ze_module_build_log_handle_t )
245+
{
246+
return ZE_RESULT_SUCCESS;
247+
};
248+
249+
//////////////////////////////////////////////////////////////////////////
250+
zeDdiTable.ModuleBuildLog.pfnGetString = [](
251+
ze_module_build_log_handle_t,
252+
size_t* pSize,
253+
char* pBuildLog )
254+
{
255+
const char* log = "Build log not available.";
256+
*pSize = strlen(log) + 1;
257+
if (pBuildLog) {
258+
#if defined(_WIN32)
259+
strncpy_s( pBuildLog, *pSize, log, *pSize );
260+
#else
261+
strncpy( pBuildLog, log, *pSize );
262+
#endif
263+
}
264+
return ZE_RESULT_SUCCESS;
265+
};
266+
267+
//////////////////////////////////////////////////////////////////////////
268+
zeDdiTable.PhysicalMem.pfnCreate = [](
269+
ze_context_handle_t,
270+
ze_device_handle_t,
271+
ze_physical_mem_desc_t*,
272+
ze_physical_mem_handle_t* phPhysicalMemory )
273+
{
274+
*phPhysicalMemory = reinterpret_cast<ze_physical_mem_handle_t>(context.get());
275+
return ZE_RESULT_SUCCESS;
276+
};
277+
278+
//////////////////////////////////////////////////////////////////////////
279+
zeDdiTable.PhysicalMem.pfnDestroy = []( ze_context_handle_t,
280+
ze_physical_mem_handle_t )
281+
{
282+
return ZE_RESULT_SUCCESS;
283+
};
284+
//////////////////////////////////////////////////////////////////////////
285+
zeDdiTable.Fence.pfnCreate = [](
286+
ze_command_queue_handle_t,
287+
const ze_fence_desc_t*,
288+
ze_fence_handle_t* phFence )
289+
{
290+
*phFence = reinterpret_cast<ze_fence_handle_t>(context.get());
291+
return ZE_RESULT_SUCCESS;
292+
};
293+
294+
//////////////////////////////////////////////////////////////////////////
295+
zeDdiTable.Fence.pfnDestroy = [](
296+
ze_fence_handle_t )
297+
{
298+
return ZE_RESULT_SUCCESS;
299+
};
300+
301+
//////////////////////////////////////////////////////////////////////////
302+
zeDdiTable.Image.pfnCreate = [](
303+
ze_context_handle_t,
304+
ze_device_handle_t,
305+
const ze_image_desc_t*,
306+
ze_image_handle_t* phImage )
307+
{
308+
*phImage = reinterpret_cast<ze_image_handle_t>(context.get());
309+
return ZE_RESULT_SUCCESS;
310+
};
311+
312+
//////////////////////////////////////////////////////////////////////////
313+
zeDdiTable.Image.pfnDestroy = [](
314+
ze_image_handle_t )
315+
{
316+
return ZE_RESULT_SUCCESS;
317+
};
318+
319+
//////////////////////////////////////////////////////////////////////////
320+
zeDdiTable.Sampler.pfnCreate = [](
321+
ze_context_handle_t,
322+
ze_device_handle_t,
323+
const ze_sampler_desc_t*,
324+
ze_sampler_handle_t* phSampler )
325+
{
326+
*phSampler = reinterpret_cast<ze_sampler_handle_t>(context.get());
327+
return ZE_RESULT_SUCCESS;
328+
};
329+
330+
//////////////////////////////////////////////////////////////////////////
331+
zeDdiTable.Sampler.pfnDestroy = [](
332+
ze_sampler_handle_t )
333+
{
334+
return ZE_RESULT_SUCCESS;
335+
};
336+
337+
//////////////////////////////////////////////////////////////////////////
338+
zeDdiTable.Kernel.pfnCreate = [](
339+
ze_module_handle_t,
340+
const ze_kernel_desc_t*,
341+
ze_kernel_handle_t* phKernel )
342+
{
343+
*phKernel = reinterpret_cast<ze_kernel_handle_t>(context.get());
344+
return ZE_RESULT_SUCCESS;
345+
};
346+
347+
//////////////////////////////////////////////////////////////////////////
348+
zeDdiTable.Kernel.pfnDestroy = [](
349+
ze_kernel_handle_t )
350+
{
351+
return ZE_RESULT_SUCCESS;
352+
};
141353

142354
//////////////////////////////////////////////////////////////////////////
143355
zeDdiTable.Device.pfnGetProperties = [](
@@ -378,6 +590,18 @@ namespace driver
378590
pCore.Driver = &zeDdiTable.Driver;
379591
pCore.Device = &zeDdiTable.Device;
380592
pCore.Mem = &zeDdiTable.Mem;
593+
pCore.CommandList = &zeDdiTable.CommandList;
594+
pCore.CommandQueue = &zeDdiTable.CommandQueue;
595+
pCore.Context = &zeDdiTable.Context;
596+
pCore.Event = &zeDdiTable.Event;
597+
pCore.EventPool = &zeDdiTable.EventPool;
598+
pCore.Module = &zeDdiTable.Module;
599+
pCore.ModuleBuildLog = &zeDdiTable.ModuleBuildLog;
600+
pCore.PhysicalMem = &zeDdiTable.PhysicalMem;
601+
pCore.Kernel = &zeDdiTable.Kernel;
602+
pCore.Fence = &zeDdiTable.Fence;
603+
pCore.Image = &zeDdiTable.Image;
604+
pCore.Sampler = &zeDdiTable.Sampler;
381605
pCore.isValidFlag = 1;
382606
pCore.version = ZE_API_VERSION_CURRENT;
383607
pTools.MetricGroup = &zetDdiTable.MetricGroup;

source/inc/ze_singleton.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <memory>
1010
#include <unordered_map>
1111
#include <mutex>
12+
#include <iostream>
1213

1314
//////////////////////////////////////////////////////////////////////////
1415
/// a abstract factory for creation of singleton objects
@@ -63,6 +64,12 @@ class singleton_factory_t
6364
return iter->second.get();
6465
}
6566

67+
bool hasInstance( _key_t _key )
68+
{
69+
std::lock_guard<std::mutex> lk( mut );
70+
return map.find( getKey( _key ) ) != map.end();
71+
}
72+
6673
//////////////////////////////////////////////////////////////////////////
6774
/// once the key is no longer valid, release the singleton
6875
void release( _key_t _key )

0 commit comments

Comments
 (0)