-
Notifications
You must be signed in to change notification settings - Fork 769
[SYCL] Fix opencl/sycl interoperability #2234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// REQUIRES: opencl | ||
|
||
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out -L %opencl_libs_dir -lOpenCL | ||
nawrinsu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// RUN: %CPU_RUN_PLACEHOLDER %t.out | ||
// RUN: %GPU_RUN_PLACEHOLDER %t.out | ||
nawrinsu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// RUN: %ACC_RUN_PLACEHOLDER %t.out | ||
|
||
#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() && | ||
"SYCL returns invalid OpenCL platform id"); | ||
|
||
cl_device_id ocl_device = selectOpenCLDevice(ocl_platform); | ||
cl::sycl::device syclDev(ocl_device); | ||
assert(ocl_device == syclDev.get() && | ||
"SYCL returns invalid OpenCL device id"); | ||
|
||
cl_context ocl_context = createOpenCLContext(ocl_platform, ocl_device); | ||
cl::sycl::context syclContext(ocl_context); | ||
assert(ocl_context == syclContext.get() && | ||
"SYCL returns invalid OpenCL context id"); | ||
|
||
return 0; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.