@@ -38,30 +38,21 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(context, DPCTLSyclContextRef)
38
38
DEFINE_SIMPLE_CONVERSION_FUNCTIONS (program, DPCTLSyclProgramRef)
39
39
DEFINE_SIMPLE_CONVERSION_FUNCTIONS (kernel, DPCTLSyclKernelRef)
40
40
41
- } /* end of anonymous namespace */
42
-
43
41
__dpctl_give DPCTLSyclProgramRef
44
- DPCTLProgram_CreateFromOCLSpirv (__dpctl_keep const DPCTLSyclContextRef CtxRef ,
45
- __dpctl_keep const void *IL,
46
- size_t length)
42
+ createOpenCLInterOpProgram ( const context &SyclCtx ,
43
+ __dpctl_keep const void *IL,
44
+ size_t length)
47
45
{
48
46
cl_int err;
49
- context *SyclCtx;
50
- if (!CtxRef) {
51
- // \todo handle error
52
- return nullptr ;
53
- }
54
-
55
- SyclCtx = unwrap (CtxRef);
56
- auto CLCtx = SyclCtx->get ();
47
+ auto CLCtx = SyclCtx.get ();
57
48
auto CLProgram = clCreateProgramWithIL (CLCtx, IL, length, &err);
58
49
if (err) {
59
50
// \todo: record the error string and any other information.
60
51
std::cerr << " OpenCL program could not be created from the SPIR-V "
61
52
" binary. OpenCL Error " << err << " .\n " ;
62
53
return nullptr ;
63
54
}
64
- auto SyclDevices = SyclCtx-> get_devices ();
55
+ auto SyclDevices = SyclCtx. get_devices ();
65
56
66
57
// Get a list of CL Devices from the Sycl devices
67
58
auto CLDevices = new cl_device_id [SyclDevices.size ()];
@@ -83,18 +74,50 @@ DPCTLProgram_CreateFromOCLSpirv (__dpctl_keep const DPCTLSyclContextRef CtxRef,
83
74
84
75
// Create the Sycl program from OpenCL program
85
76
try {
86
- auto SyclProgram = new program (* SyclCtx, CLProgram);
77
+ auto SyclProgram = new program (SyclCtx, CLProgram);
87
78
return wrap (SyclProgram);
88
- } catch (invalid_object_error) {
79
+ } catch (invalid_object_error &e ) {
89
80
// \todo record error
81
+ std::cerr << e.what () << ' \n ' ;
90
82
return nullptr ;
91
83
}
92
84
}
93
85
86
+ } /* end of anonymous namespace */
87
+
88
+ __dpctl_give DPCTLSyclProgramRef
89
+ DPCTLProgram_CreateFromOCLSpirv (__dpctl_keep const DPCTLSyclContextRef CtxRef,
90
+ __dpctl_keep const void *IL,
91
+ size_t length)
92
+ {
93
+ DPCTLSyclProgramRef Pref = nullptr ;
94
+ context *SyclCtx = nullptr ;
95
+ if (!CtxRef) {
96
+ // \todo handle error
97
+ return Pref;
98
+ }
99
+
100
+ SyclCtx = unwrap (CtxRef);
101
+ // get the backend type
102
+ auto BE = SyclCtx->get_platform ().get_backend ();
103
+ switch (BE)
104
+ {
105
+ case backend::opencl:
106
+ Pref = createOpenCLInterOpProgram (*SyclCtx, IL, length);
107
+ break ;
108
+ case backend::level_zero:
109
+ break ;
110
+ default :
111
+ break ;
112
+ }
113
+
114
+ return Pref;
115
+ }
116
+
94
117
__dpctl_give DPCTLSyclProgramRef
95
118
DPCTLProgram_CreateFromOCLSource (__dpctl_keep const DPCTLSyclContextRef Ctx,
96
- __dpctl_keep const char *Source,
97
- __dpctl_keep const char *CompileOpts)
119
+ __dpctl_keep const char *Source,
120
+ __dpctl_keep const char *CompileOpts)
98
121
{
99
122
std::string compileOpts;
100
123
context *SyclCtx = nullptr ;
@@ -118,23 +141,43 @@ DPCTLProgram_CreateFromOCLSource (__dpctl_keep const DPCTLSyclContextRef Ctx,
118
141
compileOpts = CompileOpts;
119
142
}
120
143
121
- try {
122
- SyclProgram->build_with_source (source, compileOpts);
123
- return wrap (SyclProgram);
124
- } catch (compile_program_error) {
125
- delete SyclProgram;
126
- // \todo record error
144
+ // get the backend type
145
+ auto BE = SyclCtx->get_platform ().get_backend ();
146
+ switch (BE)
147
+ {
148
+ case backend::opencl:
149
+ try {
150
+ SyclProgram->build_with_source (source, compileOpts);
151
+ return wrap (SyclProgram);
152
+ } catch (compile_program_error &e) {
153
+ std::cerr << e.what () << ' \n ' ;
154
+ delete SyclProgram;
155
+ // \todo record error
156
+ return nullptr ;
157
+ } catch (feature_not_supported &e) {
158
+ std::cerr << e.what () << ' \n ' ;
159
+ delete SyclProgram;
160
+ // \todo record error
161
+ return nullptr ;
162
+ } catch (runtime_error &e) {
163
+ std::cerr << e.what () << ' \n ' ;
164
+ delete SyclProgram;
165
+ // \todo record error
166
+ return nullptr ;
167
+ }
168
+ break ;
169
+ case backend::level_zero:
170
+ std::cerr << " CreateFromSource is not supported in Level Zero.\n " ;
127
171
return nullptr ;
128
- } catch (feature_not_supported) {
129
- delete SyclProgram;
130
- // \todo record error
172
+ default :
173
+ std::cerr << " CreateFromSource is not supported in unknown backend.\n " ;
131
174
return nullptr ;
132
175
}
133
176
}
134
177
135
178
__dpctl_give DPCTLSyclKernelRef
136
179
DPCTLProgram_GetKernel (__dpctl_keep DPCTLSyclProgramRef PRef,
137
- __dpctl_keep const char *KernelName)
180
+ __dpctl_keep const char *KernelName)
138
181
{
139
182
if (!PRef) {
140
183
// \todo record error
@@ -149,15 +192,16 @@ DPCTLProgram_GetKernel (__dpctl_keep DPCTLSyclProgramRef PRef,
149
192
try {
150
193
auto SyclKernel = new kernel (SyclProgram->get_kernel (name));
151
194
return wrap (SyclKernel);
152
- } catch (invalid_object_error) {
195
+ } catch (invalid_object_error &e ) {
153
196
// \todo record error
197
+ std::cerr << e.what () << ' \n ' ;
154
198
return nullptr ;
155
199
}
156
200
}
157
201
158
202
bool
159
203
DPCTLProgram_HasKernel (__dpctl_keep DPCTLSyclProgramRef PRef,
160
- __dpctl_keep const char *KernelName)
204
+ __dpctl_keep const char *KernelName)
161
205
{
162
206
if (!PRef) {
163
207
// \todo handle error
@@ -167,7 +211,8 @@ DPCTLProgram_HasKernel (__dpctl_keep DPCTLSyclProgramRef PRef,
167
211
auto SyclProgram = unwrap (PRef);
168
212
try {
169
213
return SyclProgram->has_kernel (KernelName);
170
- } catch (invalid_object_error) {
214
+ } catch (invalid_object_error &e) {
215
+ std::cerr << e.what () << ' \n ' ;
171
216
return false ;
172
217
}
173
218
}
0 commit comments