Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sycl/source/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ context::context(const vector_class<device> &DeviceList,
}
}
context::context(cl_context ClContext, async_handler AsyncHandler) {
const auto &Plugin = RT::getPlugin<backend::opencl>();
impl = std::make_shared<detail::context_impl>(
detail::pi::cast<detail::RT::PiContext>(ClContext), AsyncHandler,
*RT::GlobalPlugin);
detail::pi::cast<detail::RT::PiContext>(ClContext), AsyncHandler, Plugin);
}

#define PARAM_TRAITS_SPEC(param_type, param, ret_type) \
Expand Down
3 changes: 2 additions & 1 deletion sycl/source/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ device::device() : impl(std::make_shared<detail::device_impl>()) {}

device::device(cl_device_id deviceId)
: impl(std::make_shared<detail::device_impl>(
detail::pi::cast<pi_native_handle>(deviceId), *RT::GlobalPlugin)) {
detail::pi::cast<pi_native_handle>(deviceId),
RT::getPlugin<backend::opencl>())) {
// The implementation constructor takes ownership of the native handle so we
// must retain it in order to adhere to SYCL 1.2.1 spec (Rev6, section 4.3.1.)
clRetainDevice(deviceId);
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ platform::platform() : impl(std::make_shared<detail::platform_impl>()) {}
platform::platform(cl_platform_id PlatformId)
: impl(std::make_shared<detail::platform_impl>(
detail::pi::cast<detail::RT::PiPlatform>(PlatformId),
RT::GlobalPlugin)) {}
RT::getPlugin<backend::opencl>())) {}
Comment thread
s-kanaev marked this conversation as resolved.

platform::platform(const device_selector &dev_selector) {
*this = dev_selector.select_device().get_platform();
Expand Down
77 changes: 77 additions & 0 deletions sycl/test/basic_tests/opencl_interop.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// REQUIRES: opencl

// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out -L %opencl_libs_dir -lOpenCL
Comment thread
nawrinsu marked this conversation as resolved.
Outdated
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out
Comment thread
nawrinsu marked this conversation as resolved.

#include <CL/sycl.hpp>
#include <cassert>
#include <exception>
#include <vector>

#define CL_CHECK_ERRORS(ERR) \
if (ERR != CL_SUCCESS) { \
throw std::runtime_error("Error in OpenCL object creation."); \
}

cl_platform_id selectOpenCLPlatform() {
cl_int err = 0;
cl_uint num_of_platforms = 0;

err = clGetPlatformIDs(0, NULL, &num_of_platforms);
CL_CHECK_ERRORS(err);

std::vector<cl_platform_id> platforms(num_of_platforms);

err = clGetPlatformIDs(num_of_platforms, &platforms[0], 0);
CL_CHECK_ERRORS(err);

return platforms[0];
}

cl_device_id selectOpenCLDevice(cl_platform_id platform) {
cl_int err = 0;
cl_uint num_of_devices = 0;

err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 0, 0, &num_of_devices);
CL_CHECK_ERRORS(err);

std::vector<cl_device_id> devices(num_of_devices);

err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, num_of_devices,
&devices[0], 0);
CL_CHECK_ERRORS(err);

return devices[0];
}

cl_context createOpenCLContext(cl_platform_id platform, cl_device_id device) {
cl_int err = 0;
cl_context context;
std::vector<cl_context_properties> context_props(3);

context_props[0] = CL_CONTEXT_PLATFORM;
context_props[1] = cl_context_properties(platform);
context_props.back() = 0;

context = clCreateContext(&context_props[0], 1, &device, 0, 0, &err);
CL_CHECK_ERRORS(err);

return context;
}

int main() {
cl_platform_id ocl_platform = selectOpenCLPlatform();
cl::sycl::platform syclPlt(ocl_platform);
assert(ocl_platform == syclPlt.get());
Comment thread
nawrinsu marked this conversation as resolved.
Outdated

cl_device_id ocl_device = selectOpenCLDevice(ocl_platform);
cl::sycl::device syclDev(ocl_device);
assert(ocl_device == syclDev.get());

cl_context ocl_context = createOpenCLContext(ocl_platform, ocl_device);
cl::sycl::context syclContext(ocl_context);
assert(ocl_context == syclContext.get());

return 0;
}