32
32
33
33
using namespace sycl ;
34
34
35
+ namespace
36
+ {
37
+ using namespace dpctl ::syclinterface;
38
+ } // end of anonymous namespace
39
+
35
40
__dpctl_give DPCTLSyclContextRef
36
41
DPCTLContext_Create (__dpctl_keep const DPCTLSyclDeviceRef DRef,
37
42
error_handler_callback *handler,
38
43
int /* */ )
39
44
{
40
45
DPCTLSyclContextRef CRef = nullptr ;
41
- auto Device = unwrap (DRef);
46
+ auto Device = unwrap<device> (DRef);
42
47
if (!Device) {
43
48
error_handler (" Cannot create device from DPCTLSyclDeviceRef"
44
49
" as input is a nullptr." ,
45
50
__FILE__, __func__, __LINE__);
46
51
return nullptr ;
47
52
}
48
53
try {
49
- CRef = wrap (new context (*Device, DPCTL_AsyncErrorHandler (handler)));
54
+ CRef = wrap<context>(
55
+ new context (*Device, DPCTL_AsyncErrorHandler (handler)));
50
56
} catch (std::exception const &e) {
51
57
error_handler (e, __FILE__, __func__, __LINE__);
52
58
}
@@ -61,7 +67,7 @@ DPCTLContext_CreateFromDevices(__dpctl_keep const DPCTLDeviceVectorRef DVRef,
61
67
{
62
68
DPCTLSyclContextRef CRef = nullptr ;
63
69
std::vector<device> Devices;
64
- auto DeviceRefs = unwrap (DVRef);
70
+ auto DeviceRefs = unwrap<std::vector<DPCTLSyclDeviceRef>> (DVRef);
65
71
if (!DeviceRefs) {
66
72
error_handler (" Cannot create device reference from DPCTLDeviceVectorRef"
67
73
" as input is a nullptr." ,
@@ -71,11 +77,12 @@ DPCTLContext_CreateFromDevices(__dpctl_keep const DPCTLDeviceVectorRef DVRef,
71
77
Devices.reserve (DeviceRefs->size ());
72
78
73
79
for (auto const &DRef : *DeviceRefs) {
74
- Devices.emplace_back (*unwrap (DRef));
80
+ Devices.emplace_back (*unwrap<device> (DRef));
75
81
}
76
82
77
83
try {
78
- CRef = wrap (new context (Devices, DPCTL_AsyncErrorHandler (handler)));
84
+ CRef = wrap<context>(
85
+ new context (Devices, DPCTL_AsyncErrorHandler (handler)));
79
86
} catch (std::exception const &e) {
80
87
error_handler (e, __FILE__, __func__, __LINE__);
81
88
}
@@ -91,21 +98,21 @@ bool DPCTLContext_AreEq(__dpctl_keep const DPCTLSyclContextRef CtxRef1,
91
98
__LINE__);
92
99
return false ;
93
100
}
94
- return (*unwrap (CtxRef1) == *unwrap (CtxRef2));
101
+ return (*unwrap<context> (CtxRef1) == *unwrap<context> (CtxRef2));
95
102
}
96
103
97
104
__dpctl_give DPCTLSyclContextRef
98
105
DPCTLContext_Copy (__dpctl_keep const DPCTLSyclContextRef CRef)
99
106
{
100
- auto Context = unwrap (CRef);
107
+ auto Context = unwrap<context> (CRef);
101
108
if (!Context) {
102
109
error_handler (" Cannot copy DPCTLSyclContextRef as input is a nullptr." ,
103
110
__FILE__, __func__, __LINE__);
104
111
return nullptr ;
105
112
}
106
113
try {
107
114
auto CopiedContext = new context (*Context);
108
- return wrap (CopiedContext);
115
+ return wrap<context> (CopiedContext);
109
116
} catch (std::exception const &e) {
110
117
error_handler (e, __FILE__, __func__, __LINE__);
111
118
return nullptr ;
@@ -115,16 +122,17 @@ DPCTLContext_Copy(__dpctl_keep const DPCTLSyclContextRef CRef)
115
122
__dpctl_give DPCTLDeviceVectorRef
116
123
DPCTLContext_GetDevices (__dpctl_keep const DPCTLSyclContextRef CRef)
117
124
{
118
- auto Context = unwrap (CRef);
125
+ auto Context = unwrap<context> (CRef);
119
126
if (!Context) {
120
127
error_handler (" Cannot retrieve devices from DPCTLSyclContextRef as "
121
128
" input is a nullptr." ,
122
129
__FILE__, __func__, __LINE__);
123
130
return nullptr ;
124
131
}
125
- std::vector<DPCTLSyclDeviceRef> *DevicesVectorPtr = nullptr ;
132
+ using vecTy = std::vector<DPCTLSyclDeviceRef>;
133
+ vecTy *DevicesVectorPtr = nullptr ;
126
134
try {
127
- DevicesVectorPtr = new std::vector<DPCTLSyclDeviceRef> ();
135
+ DevicesVectorPtr = new vecTy ();
128
136
} catch (std::exception const &e) {
129
137
delete DevicesVectorPtr;
130
138
error_handler (e, __FILE__, __func__, __LINE__);
@@ -134,9 +142,9 @@ DPCTLContext_GetDevices(__dpctl_keep const DPCTLSyclContextRef CRef)
134
142
auto Devices = Context->get_devices ();
135
143
DevicesVectorPtr->reserve (Devices.size ());
136
144
for (const auto &Dev : Devices) {
137
- DevicesVectorPtr->emplace_back (wrap (new device (Dev)));
145
+ DevicesVectorPtr->emplace_back (wrap<device> (new device (Dev)));
138
146
}
139
- return wrap (DevicesVectorPtr);
147
+ return wrap<vecTy> (DevicesVectorPtr);
140
148
} catch (std::exception const &e) {
141
149
delete DevicesVectorPtr;
142
150
error_handler (e, __FILE__, __func__, __LINE__);
@@ -146,7 +154,7 @@ DPCTLContext_GetDevices(__dpctl_keep const DPCTLSyclContextRef CRef)
146
154
147
155
size_t DPCTLContext_DeviceCount (__dpctl_keep const DPCTLSyclContextRef CRef)
148
156
{
149
- auto Context = unwrap (CRef);
157
+ auto Context = unwrap<context> (CRef);
150
158
if (!Context) {
151
159
error_handler (" Cannot retrieve devices from DPCTLSyclContextRef as "
152
160
" input is a nullptr." ,
@@ -159,7 +167,7 @@ size_t DPCTLContext_DeviceCount(__dpctl_keep const DPCTLSyclContextRef CRef)
159
167
160
168
bool DPCTLContext_IsHost (__dpctl_keep const DPCTLSyclContextRef CtxRef)
161
169
{
162
- auto Ctx = unwrap (CtxRef);
170
+ auto Ctx = unwrap<context> (CtxRef);
163
171
if (Ctx) {
164
172
return Ctx->is_host ();
165
173
}
@@ -168,7 +176,7 @@ bool DPCTLContext_IsHost(__dpctl_keep const DPCTLSyclContextRef CtxRef)
168
176
169
177
void DPCTLContext_Delete (__dpctl_take DPCTLSyclContextRef CtxRef)
170
178
{
171
- delete unwrap (CtxRef);
179
+ delete unwrap<context> (CtxRef);
172
180
}
173
181
174
182
DPCTLSyclBackendType
@@ -178,7 +186,7 @@ DPCTLContext_GetBackend(__dpctl_keep const DPCTLSyclContextRef CtxRef)
178
186
return DPCTL_UNKNOWN_BACKEND;
179
187
}
180
188
181
- auto BE = unwrap (CtxRef)->get_platform ().get_backend ();
189
+ auto BE = unwrap<context> (CtxRef)->get_platform ().get_backend ();
182
190
183
191
switch (BE) {
184
192
case backend::host:
@@ -197,7 +205,7 @@ DPCTLContext_GetBackend(__dpctl_keep const DPCTLSyclContextRef CtxRef)
197
205
size_t DPCTLContext_Hash (__dpctl_keep const DPCTLSyclContextRef CtxRef)
198
206
{
199
207
if (CtxRef) {
200
- auto C = unwrap (CtxRef);
208
+ auto C = unwrap<context> (CtxRef);
201
209
std::hash<context> hash_fn;
202
210
return hash_fn (*C);
203
211
}
0 commit comments