Skip to content

Commit aa7e72d

Browse files
committed
Add support for handling old and new handles used in handle translation
Signed-off-by: Neil R. Spruit <[email protected]>
1 parent 256c091 commit aa7e72d

File tree

5 files changed

+1463
-24
lines changed

5 files changed

+1463
-24
lines changed

source/drivers/null/ze_null.cpp

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

7980
return ZE_RESULT_SUCCESS;
8081
};
81-
82-
//pfnGetIPCProperties
8382

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

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

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

141353
//////////////////////////////////////////////////////////////////////////
142354
zeDdiTable.Device.pfnGetProperties = [](
@@ -373,6 +585,18 @@ namespace driver
373585
pCore.Driver = &zeDdiTable.Driver;
374586
pCore.Device = &zeDdiTable.Device;
375587
pCore.Mem = &zeDdiTable.Mem;
588+
pCore.CommandList = &zeDdiTable.CommandList;
589+
pCore.CommandQueue = &zeDdiTable.CommandQueue;
590+
pCore.Context = &zeDdiTable.Context;
591+
pCore.Event = &zeDdiTable.Event;
592+
pCore.EventPool = &zeDdiTable.EventPool;
593+
pCore.Module = &zeDdiTable.Module;
594+
pCore.ModuleBuildLog = &zeDdiTable.ModuleBuildLog;
595+
pCore.PhysicalMem = &zeDdiTable.PhysicalMem;
596+
pCore.Kernel = &zeDdiTable.Kernel;
597+
pCore.Fence = &zeDdiTable.Fence;
598+
pCore.Image = &zeDdiTable.Image;
599+
pCore.Sampler = &zeDdiTable.Sampler;
376600
pCore.isValidFlag = 1;
377601
pCore.version = ZE_API_VERSION_CURRENT;
378602
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)