Skip to content

Commit 598cd18

Browse files
Kerilkbashbaug
andcommitted
Deinitialization support.
Co-authored-by: Ben Ashbaugh <ben.ashbaugh@intel.com>
1 parent 634ef47 commit 598cd18

File tree

14 files changed

+606
-68
lines changed

14 files changed

+606
-68
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ set (OPENCL_COMPILE_DEFINITIONS
161161
CL_NO_NON_ICD_DISPATCH_EXTENSION_PROTOTYPES
162162
OPENCL_ICD_LOADER_VERSION_MAJOR=3
163163
OPENCL_ICD_LOADER_VERSION_MINOR=0
164-
OPENCL_ICD_LOADER_VERSION_REV=7
164+
OPENCL_ICD_LOADER_VERSION_REV=8
165165
$<$<BOOL:${ENABLE_OPENCL_LAYERS}>:CL_ENABLE_LAYERS>
166166
$<$<BOOL:${ENABLE_OPENCL_LOADER_MANAGED_DISPATCH}>:CL_ENABLE_LOADER_MANAGED_DISPATCH>
167167
)

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,5 @@ The following debug environment variables are available for use with the OpenCL
145145
| OPENCL_LAYERS | Specifies a list of layers to load. | `export OPENCL_LAYERS=libLayerA.so:libLayerB.so`<br/><br/>`set OPENCL_LAYERS=libLayerA.dll;libLayerB.dll` |
146146
| OPENCL_LAYER_PATH | On Linux and Android, specifies a directory to scan for layers to enumerate in place of the default `/etc/OpenCL/layers'. | `export OPENCL_LAYER_PATH=/my/local/layers/search/path` |
147147
| OCL_ICD_ENABLE_TRACE | Enable the trace mechanism | `export OCL_ICD_ENABLE_TRACE=True`<br/><br/>`set OCL_ICD_ENABLE_TRACE=True`<br/>`true, T, 1 can also be used here.` |
148+
| OCL_ICD_FORCE_LEGACY_TERMINATION | Forces using the legacy termination scheme. Legacy termination supports older layers, but does not support layer de-initialization and does not close library handles for layers or ICDs. | `export OCL_ICD_FORCE_LEGACY_TERMINATION=True`<br/><br/>`set OCL_ICD_FORCE_LEGACY_TERMINATION=True`<br/>`true, T, 1 can also be used here.` |
149+
| OCL_ICD_DISABLE_DYNAMIC_LIBRARY_UNLOADING | Prevents the ICD loader from closing dynamic library handles for layers and ICDs. This can be used for debugging purposes or to allow leak sanitizers to have full stack traces. | `export OCL_ICD_DISABLE_DYNAMIC_LIBRARY_UNLOADING=True`<br/><br/>`set OCL_ICD_DISABLE_DYNAMIC_LIBRARY_UNLOADING=True`<br/>`true, T, 1 can also be used here.` |

include/cl_khr_icd2.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,31 @@
1818

1919
#include <CL/cl.h>
2020

21+
#if !defined(CL_PLATFORM_UNLOADABLE_KHR)
22+
#define CL_PLATFORM_UNLOADABLE_KHR 0x0921
23+
#endif
24+
25+
#if defined(CL_ENABLE_LAYERS) && !defined(CL_LAYER_PROPERTIES_LIST_END)
26+
typedef cl_properties cl_layer_properties;
27+
28+
#define CL_LAYER_PROPERTIES_LIST_END ((cl_layer_properties)0)
29+
30+
typedef cl_int CL_API_CALL
31+
clInitLayerWithProperties_t(
32+
cl_uint num_entries,
33+
const cl_icd_dispatch *target_dispatch,
34+
cl_uint *num_entries_ret,
35+
const cl_icd_dispatch **layer_dispatch_ret,
36+
const cl_layer_properties *properties);
37+
38+
typedef clInitLayerWithProperties_t *pfn_clInitLayerWithProperties;
39+
40+
typedef cl_int CL_API_CALL
41+
clDeinitLayer_t(void);
42+
43+
typedef clDeinitLayer_t *pfn_clDeinitLayer;
44+
#endif //defined(CL_ENABLE_LAYERS) && !defined(CL_LAYER_PROPERTIES_LIST_END)
45+
2146
#if !defined(CL_ICD2_TAG_KHR)
2247
#if INTPTR_MAX == INT32_MAX
2348
#define CL_ICD2_TAG_KHR ((intptr_t)0x434C3331)

loader/cllayerinfo.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "icd.h"
2020
#include <stdio.h>
2121
#include <stdlib.h>
22-
#include <CL/cl_layer.h>
2322
#if defined(_WIN32)
2423
#include <io.h>
2524
#include <share.h>
@@ -90,7 +89,7 @@ static void restore_outputs(void)
9089
void printLayerInfo(const struct KHRLayer *layer)
9190
{
9291
cl_layer_api_version api_version = 0;
93-
pfn_clGetLayerInfo p_clGetLayerInfo = (pfn_clGetLayerInfo)(size_t)layer->p_clGetLayerInfo;
92+
pfn_clGetLayerInfo p_clGetLayerInfo = layer->p_clGetLayerInfo;
9493
cl_int result = CL_SUCCESS;
9594
size_t sz;
9695

@@ -113,20 +112,26 @@ void printLayerInfo(const struct KHRLayer *layer)
113112
}
114113
}
115114

116-
int main (int argc, char *argv[])
115+
static void run_silently(void (*pfn)(void))
117116
{
118-
(void)argc;
119-
(void)argv;
120117
silence_layers();
121118
atexit(restore_outputs);
122-
khrIcdInitialize();
119+
pfn();
123120
restore_outputs();
124121
atexit(silence_layers);
122+
}
123+
124+
int main (int argc, char *argv[])
125+
{
126+
(void)argc;
127+
(void)argv;
128+
run_silently(&khrIcdInitialize);
125129
const struct KHRLayer *layer = khrFirstLayer;
126130
while (layer)
127131
{
128132
printLayerInfo(layer);
129133
layer = layer->next;
130134
}
135+
run_silently(&khrIcdDeinitialize);
131136
return 0;
132137
}

0 commit comments

Comments
 (0)