@@ -38,30 +38,21 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(context, DPCTLSyclContextRef)
3838DEFINE_SIMPLE_CONVERSION_FUNCTIONS (program, DPCTLSyclProgramRef)
3939DEFINE_SIMPLE_CONVERSION_FUNCTIONS (kernel, DPCTLSyclKernelRef)
4040
41- } /* end of anonymous namespace */
42-
4341__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)
4745{
4846 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 ();
5748 auto CLProgram = clCreateProgramWithIL (CLCtx, IL, length, &err);
5849 if (err) {
5950 // \todo: record the error string and any other information.
6051 std::cerr << " OpenCL program could not be created from the SPIR-V "
6152 " binary. OpenCL Error " << err << " .\n " ;
6253 return nullptr ;
6354 }
64- auto SyclDevices = SyclCtx-> get_devices ();
55+ auto SyclDevices = SyclCtx. get_devices ();
6556
6657 // Get a list of CL Devices from the Sycl devices
6758 auto CLDevices = new cl_device_id[SyclDevices.size ()];
@@ -83,18 +74,50 @@ DPCTLProgram_CreateFromOCLSpirv (__dpctl_keep const DPCTLSyclContextRef CtxRef,
8374
8475 // Create the Sycl program from OpenCL program
8576 try {
86- auto SyclProgram = new program (* SyclCtx, CLProgram);
77+ auto SyclProgram = new program (SyclCtx, CLProgram);
8778 return wrap (SyclProgram);
88- } catch (invalid_object_error) {
79+ } catch (invalid_object_error &e ) {
8980 // \todo record error
81+ std::cerr << e.what () << ' \n ' ;
9082 return nullptr ;
9183 }
9284}
9385
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+
94117__dpctl_give DPCTLSyclProgramRef
95118DPCTLProgram_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)
98121{
99122 std::string compileOpts;
100123 context *SyclCtx = nullptr ;
@@ -118,23 +141,43 @@ DPCTLProgram_CreateFromOCLSource (__dpctl_keep const DPCTLSyclContextRef Ctx,
118141 compileOpts = CompileOpts;
119142 }
120143
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 " ;
127171 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 " ;
131174 return nullptr ;
132175 }
133176}
134177
135178__dpctl_give DPCTLSyclKernelRef
136179DPCTLProgram_GetKernel (__dpctl_keep DPCTLSyclProgramRef PRef,
137- __dpctl_keep const char *KernelName)
180+ __dpctl_keep const char *KernelName)
138181{
139182 if (!PRef) {
140183 // \todo record error
@@ -149,15 +192,16 @@ DPCTLProgram_GetKernel (__dpctl_keep DPCTLSyclProgramRef PRef,
149192 try {
150193 auto SyclKernel = new kernel (SyclProgram->get_kernel (name));
151194 return wrap (SyclKernel);
152- } catch (invalid_object_error) {
195+ } catch (invalid_object_error &e ) {
153196 // \todo record error
197+ std::cerr << e.what () << ' \n ' ;
154198 return nullptr ;
155199 }
156200}
157201
158202bool
159203DPCTLProgram_HasKernel (__dpctl_keep DPCTLSyclProgramRef PRef,
160- __dpctl_keep const char *KernelName)
204+ __dpctl_keep const char *KernelName)
161205{
162206 if (!PRef) {
163207 // \todo handle error
@@ -167,7 +211,8 @@ DPCTLProgram_HasKernel (__dpctl_keep DPCTLSyclProgramRef PRef,
167211 auto SyclProgram = unwrap (PRef);
168212 try {
169213 return SyclProgram->has_kernel (KernelName);
170- } catch (invalid_object_error) {
214+ } catch (invalid_object_error &e) {
215+ std::cerr << e.what () << ' \n ' ;
171216 return false ;
172217 }
173218}
0 commit comments