Skip to content

Commit bbd586a

Browse files
authored
Merge pull request #199 from diptorupd/feature/program
Feature/program
2 parents 45959f9 + fdfdcaf commit bbd586a

25 files changed

+868
-695
lines changed

dpctl-capi/include/dpctl_sycl_program_interface.h

+4-5
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@ DPCTL_C_EXTERN_C_BEGIN
4141
* @brief Create a Sycl program from an OpenCL SPIR-V binary file.
4242
*
4343
* Sycl 1.2 does not expose any method to create a sycl::program from a SPIR-V
44-
* IL file. To get around this limitation, we need to use the Sycl feature to
45-
* create an interoperability kernel from an OpenCL kernel. This function first
46-
* creates an OpenCL program and kernel from the SPIR-V binary and then using
47-
* the Sycl-OpenCL interoperability feature creates a Sycl kernel from the
48-
* OpenCL kernel.
44+
* IL file. To get around this limitation, we first creare a SYCL
45+
* interoperability program and then create a SYCL program from the
46+
* interoperability program. Currently, interoperability programs can be created
47+
* for OpenCL and Level-0 backends.
4948
*
5049
* The feature to create a Sycl kernel from a SPIR-V IL binary will be available
5150
* in Sycl 2.0 at which point this function may become deprecated.

dpctl-capi/source/dpctl_sycl_program_interface.cpp

+76-31
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,21 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(context, DPCTLSyclContextRef)
3838
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(program, DPCTLSyclProgramRef)
3939
DEFINE_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
95118
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)
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
136179
DPCTLProgram_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

158202
bool
159203
DPCTLProgram_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
}

dpctl/__init__.pxd

+25-26
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
1-
##===-------------- __init__.pxd - dpctl module --------*- Cython -*-------===##
2-
##
3-
## Data Parallel Control (dpCtl)
4-
##
5-
## Copyright 2020 Intel Corporation
6-
##
7-
## Licensed under the Apache License, Version 2.0 (the "License");
8-
## you may not use this file except in compliance with the License.
9-
## You may obtain a copy of the License at
10-
##
11-
## http://www.apache.org/licenses/LICENSE-2.0
12-
##
13-
## Unless required by applicable law or agreed to in writing, software
14-
## distributed under the License is distributed on an "AS IS" BASIS,
15-
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16-
## See the License for the specific language governing permissions and
17-
## limitations under the License.
18-
##
19-
##===----------------------------------------------------------------------===##
20-
##
21-
## \file
22-
## This file declares the extension types and functions for the Cython API
23-
## implemented in sycl_core.pyx.
24-
##
25-
##===----------------------------------------------------------------------===##
1+
# ===------------ __init__.pxd - dpctl module --------*- Cython -*----------===#
2+
#
3+
# Data Parallel Control (dpCtl)
4+
#
5+
# Copyright 2020 Intel Corporation
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
# ===-----------------------------------------------------------------------===#
20+
#
21+
# \file
22+
# This file declares the extension types and functions for the Cython API
23+
# implemented in sycl_core.pyx.
24+
#
25+
# ===-----------------------------------------------------------------------===#
2626

2727
# distutils: language = c++
2828
# cython: language_level=3
2929

3030
from dpctl._sycl_core cimport *
3131
from dpctl._memory import *
32-

dpctl/__init__.py

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
##===----------------- __init__.py - dpctl module -------*- Cython -*------===##
2-
##
3-
## Data Parallel Control (dpCtl)
4-
##
5-
## Copyright 2020 Intel Corporation
6-
##
7-
## Licensed under the Apache License, Version 2.0 (the "License");
8-
## you may not use this file except in compliance with the License.
9-
## You may obtain a copy of the License at
10-
##
11-
## http://www.apache.org/licenses/LICENSE-2.0
12-
##
13-
## Unless required by applicable law or agreed to in writing, software
14-
## distributed under the License is distributed on an "AS IS" BASIS,
15-
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16-
## See the License for the specific language governing permissions and
17-
## limitations under the License.
18-
##
19-
##===----------------------------------------------------------------------===##
20-
##
21-
## \file
22-
## This top-level dpctl module.
23-
##
24-
##===----------------------------------------------------------------------===##
1+
# ===---------------- __init__.py - dpctl module -------*- Cython -*--------===#
2+
#
3+
# Data Parallel Control (dpCtl)
4+
#
5+
# Copyright 2020 Intel Corporation
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
# ===-----------------------------------------------------------------------===#
20+
#
21+
# \file
22+
# The top-level dpctl module.
23+
#
24+
# ===-----------------------------------------------------------------------===#
2525
"""
2626
**Data Parallel Control (dpCtl)**
2727

dpctl/_backend.pxd

+25-25
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
##===------------- backend.pyx - dpctl module -------*- Cython -*----------===##
2-
##
3-
## Data Parallel Control (dpCtl)
4-
##
5-
## Copyright 2020 Intel Corporation
6-
##
7-
## Licensed under the Apache License, Version 2.0 (the "License");
8-
## you may not use this file except in compliance with the License.
9-
## You may obtain a copy of the License at
10-
##
11-
## http://www.apache.org/licenses/LICENSE-2.0
12-
##
13-
## Unless required by applicable law or agreed to in writing, software
14-
## distributed under the License is distributed on an "AS IS" BASIS,
15-
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16-
## See the License for the specific language governing permissions and
17-
## limitations under the License.
18-
##
19-
##===----------------------------------------------------------------------===##
20-
##
21-
## \file
22-
## This file defines the Cython extern types for the functions and opaque data
23-
## types defined by dpctl's C API.
24-
##
25-
##===----------------------------------------------------------------------===##
1+
# ===------------ backend.pyx - dpctl module -------*- Cython -*------------===#
2+
#
3+
# Data Parallel Control (dpCtl)
4+
#
5+
# Copyright 2020 Intel Corporation
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
# ===-----------------------------------------------------------------------===#
20+
#
21+
# \file
22+
# This file defines the Cython extern types for the functions and opaque data
23+
# types defined by dpctl's C API.
24+
#
25+
# ===-----------------------------------------------------------------------===#
2626

2727
# distutils: language = c++
2828
# cython: language_level=3

0 commit comments

Comments
 (0)