@@ -86,8 +86,7 @@ typedef CL_API_ENTRY cl_int(CL_API_CALL *clSetProgramSpecializationConstant_fn)(
86
86
// There's another way. A mapping of context to collection of function pointers.
87
87
// Though, the former design allows for simultaneous access for different
88
88
// function pointer for different contexts.
89
- template <const char *FuncName, typename FuncT>
90
- struct ExtFuncCache {
89
+ template <const char *FuncName, typename FuncT> struct ExtFuncCache {
91
90
std::map<pi_context, FuncT> Cache;
92
91
// FIXME Use spin-lock to make lock/unlock faster and w/o context switching
93
92
std::mutex Mtx;
@@ -96,8 +95,8 @@ struct ExtFuncCache {
96
95
struct ExtFuncCacheCollection ;
97
96
98
97
namespace detail {
99
- template <const char *FuncName, typename FuncT>
100
- ExtFuncCache<FuncName, FuncT> &get (::ExtFuncCacheCollection &);
98
+ template <const char *FuncName, typename FuncT>
99
+ ExtFuncCache<FuncName, FuncT> &get (::ExtFuncCacheCollection &);
101
100
} // namespace detail
102
101
103
102
struct ExtFuncCacheCollection {
@@ -106,10 +105,9 @@ struct ExtFuncCacheCollection {
106
105
return detail::get<FuncName, FuncT>(*this );
107
106
}
108
107
109
- #define DEFINE_INTEL (t_pfx ) \
110
- ExtFuncCache<t_pfx ## Name, t_pfx ## INTEL_fn> t_pfx ## _Cache
111
- #define DEFINE (t_pfx ) \
112
- ExtFuncCache<t_pfx ## Name, t_pfx ## _fn> t_pfx ## _Cache
108
+ #define DEFINE_INTEL (t_pfx ) \
109
+ ExtFuncCache<t_pfx##Name, t_pfx##INTEL_fn> t_pfx##_Cache
110
+ #define DEFINE (t_pfx ) ExtFuncCache<t_pfx##Name, t_pfx##_fn> t_pfx##_Cache
113
111
114
112
DEFINE_INTEL (clHostMemAlloc);
115
113
DEFINE_INTEL (clDeviceMemAlloc);
@@ -128,27 +126,31 @@ struct ExtFuncCacheCollection {
128
126
};
129
127
130
128
namespace detail {
131
- #define DEFINE_GETTER_INTEL (t_pfx ) \
132
- template <> ExtFuncCache<t_pfx ## Name, t_pfx ## INTEL_fn> &get<t_pfx ## Name, t_pfx ## INTEL_fn>(::ExtFuncCacheCollection &C) { \
133
- return C.t_pfx ## _Cache; \
129
+ #define DEFINE_GETTER_INTEL (t_pfx ) \
130
+ template <> \
131
+ ExtFuncCache<t_pfx##Name, t_pfx##INTEL_fn> \
132
+ &get<t_pfx##Name, t_pfx##INTEL_fn>(::ExtFuncCacheCollection & C) { \
133
+ return C.t_pfx ##_Cache; \
134
134
}
135
- #define DEFINE_GETTER (t_pfx ) \
136
- template <> ExtFuncCache<t_pfx ## Name, t_pfx ## _fn> &get<t_pfx ## Name, t_pfx ## _fn>(::ExtFuncCacheCollection &C) { \
137
- return C.t_pfx ## _Cache; \
135
+ #define DEFINE_GETTER (t_pfx ) \
136
+ template <> \
137
+ ExtFuncCache<t_pfx##Name, t_pfx##_fn> &get<t_pfx##Name, t_pfx##_fn>( \
138
+ ::ExtFuncCacheCollection & C) { \
139
+ return C.t_pfx ##_Cache; \
138
140
}
139
141
140
- DEFINE_GETTER_INTEL (clHostMemAlloc)
141
- DEFINE_GETTER_INTEL (clDeviceMemAlloc)
142
- DEFINE_GETTER_INTEL (clSharedMemAlloc)
143
- DEFINE_GETTER_INTEL (clCreateBufferWithProperties)
144
- DEFINE_GETTER_INTEL (clMemBlockingFree)
145
- DEFINE_GETTER_INTEL (clMemFree)
146
- DEFINE_GETTER_INTEL (clSetKernelArgMemPointer)
147
- DEFINE_GETTER_INTEL (clEnqueueMemset)
148
- DEFINE_GETTER_INTEL (clEnqueueMemcpy)
149
- DEFINE_GETTER_INTEL (clGetMemAllocInfo)
150
- DEFINE_GETTER (clGetDeviceFunctionPointer)
151
- DEFINE_GETTER (clSetProgramSpecializationConstant)
142
+ DEFINE_GETTER_INTEL (clHostMemAlloc)
143
+ DEFINE_GETTER_INTEL (clDeviceMemAlloc)
144
+ DEFINE_GETTER_INTEL (clSharedMemAlloc)
145
+ DEFINE_GETTER_INTEL (clCreateBufferWithProperties)
146
+ DEFINE_GETTER_INTEL (clMemBlockingFree)
147
+ DEFINE_GETTER_INTEL (clMemFree)
148
+ DEFINE_GETTER_INTEL (clSetKernelArgMemPointer)
149
+ DEFINE_GETTER_INTEL (clEnqueueMemset)
150
+ DEFINE_GETTER_INTEL (clEnqueueMemcpy)
151
+ DEFINE_GETTER_INTEL (clGetMemAllocInfo)
152
+ DEFINE_GETTER (clGetDeviceFunctionPointer)
153
+ DEFINE_GETTER (clSetProgramSpecializationConstant)
152
154
#undef DEFINE_GETTER
153
155
#undef DEFINE_GETTER_INTEL
154
156
} // namespace detail
@@ -1470,24 +1472,25 @@ pi_result piTearDown(void *PluginParameter) {
1470
1472
}
1471
1473
1472
1474
pi_result piContextRelease (pi_context Context) {
1473
- #define RELEASE_EXT_FUNCS_CACHE_INTEL (t_pfx ) \
1474
- { \
1475
- ExtFuncCache<t_pfx ## Name, t_pfx ## INTEL_fn> &Cache = ExtFuncCaches->get <t_pfx ## Name, t_pfx ## INTEL_fn>(); \
1476
- std::lock_guard<std::mutex> CacheLock{Cache.Mtx }; \
1477
- auto It = Cache.Cache .find (Context); \
1478
- if (It != Cache.Cache .end ()) \
1479
- Cache.Cache .erase (It); \
1475
+ #define RELEASE_EXT_FUNCS_CACHE_INTEL (t_pfx ) \
1476
+ { \
1477
+ ExtFuncCache<t_pfx##Name, t_pfx##INTEL_fn> &Cache = \
1478
+ ExtFuncCaches->get <t_pfx##Name, t_pfx##INTEL_fn>(); \
1479
+ std::lock_guard<std::mutex> CacheLock{Cache.Mtx }; \
1480
+ auto It = Cache.Cache .find (Context); \
1481
+ if (It != Cache.Cache .end ()) \
1482
+ Cache.Cache .erase (It); \
1480
1483
}
1481
- #define RELEASE_EXT_FUNCS_CACHE (t_pfx ) \
1482
- { \
1483
- ExtFuncCache<t_pfx ## Name, t_pfx ## _fn> &Cache = ExtFuncCaches->get <t_pfx ## Name, t_pfx ## _fn>(); \
1484
- std::lock_guard<std::mutex> CacheLock{Cache.Mtx }; \
1485
- auto It = Cache.Cache .find (Context); \
1486
- if (It != Cache.Cache .end ()) \
1487
- Cache.Cache .erase (It); \
1484
+ #define RELEASE_EXT_FUNCS_CACHE (t_pfx ) \
1485
+ { \
1486
+ ExtFuncCache<t_pfx##Name, t_pfx##_fn> &Cache = \
1487
+ ExtFuncCaches->get <t_pfx##Name, t_pfx##_fn>(); \
1488
+ std::lock_guard<std::mutex> CacheLock{Cache.Mtx }; \
1489
+ auto It = Cache.Cache .find (Context); \
1490
+ if (It != Cache.Cache .end ()) \
1491
+ Cache.Cache .erase (It); \
1488
1492
}
1489
1493
1490
-
1491
1494
RELEASE_EXT_FUNCS_CACHE_INTEL (clHostMemAlloc);
1492
1495
RELEASE_EXT_FUNCS_CACHE_INTEL (clDeviceMemAlloc);
1493
1496
RELEASE_EXT_FUNCS_CACHE_INTEL (clSharedMemAlloc);
0 commit comments