Skip to content
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

Use new UR handles for opencl instead of casting mechanism #12172

Open
wants to merge 7 commits into
base: sycl
Choose a base branch
from

Conversation

omarahmed1111
Copy link
Contributor

@omarahmed1111 omarahmed1111 commented Dec 14, 2023

This PR changes sycl-rt for opencl interop functionality to use the new UR handles layer for opencl, instead of relying on casting directly handles directly. So, it removes the 1:1 relation between UR/sycl-rt and opencl.

The changes in this PR involves:

  • Changing sycl interop API to not own the opencl native handle passed to sycl-rt by default. SYCL application could be still using the native opencl handle outside of SYCL-RT.
  • Remove the specialized opencl retains in sycl-rt as this will retain UR objects which are already owned by sycl-rt to make it and release it. Before this PR, this was needed as sycl-rt was being passed the opencl handle itself so it could have released it while still being used in the sycl application so we needed to retain it but this PR removes the 1:1 mapping between UR handles and OpenCL handles so this should no longer be needed.
  • Moves SetArgForLocalAccessor.cpp and InteropKernelEnqueue.cpp unittests to be DeprecatedFeatures/set_arg_interop.cpp e2e-test. For more context refer to this comment

UR PR

@omarahmed1111 omarahmed1111 force-pushed the Testing-adding-handles-to-opencl branch from 3acda17 to f3f6360 Compare December 14, 2023 11:44
@omarahmed1111 omarahmed1111 force-pushed the Testing-adding-handles-to-opencl branch 3 times, most recently from 49e2da4 to 69c4f49 Compare December 15, 2023 12:24
@omarahmed1111 omarahmed1111 force-pushed the Testing-adding-handles-to-opencl branch from 69c4f49 to e95d890 Compare December 15, 2023 15:28
@omarahmed1111 omarahmed1111 force-pushed the Testing-adding-handles-to-opencl branch 3 times, most recently from bfe155f to 643dcf3 Compare December 18, 2023 17:59
@omarahmed1111 omarahmed1111 force-pushed the Testing-adding-handles-to-opencl branch from 643dcf3 to 503faa9 Compare December 19, 2023 10:39
@omarahmed1111 omarahmed1111 force-pushed the Testing-adding-handles-to-opencl branch from 503faa9 to 9eed560 Compare December 19, 2023 12:42
@omarahmed1111 omarahmed1111 force-pushed the Testing-adding-handles-to-opencl branch from 9eed560 to de060f6 Compare December 19, 2023 14:48
@omarahmed1111 omarahmed1111 force-pushed the Testing-adding-handles-to-opencl branch from de060f6 to 4ea421e Compare December 20, 2023 10:12
@omarahmed1111 omarahmed1111 force-pushed the Testing-adding-handles-to-opencl branch from 4ea421e to ce846a0 Compare December 20, 2023 12:11
Comment on lines +123 to +147
// Enqueuing an interop kernel while avoid calls to piKernelSetArg from
// different threads on the same kernel.
{
constexpr std::size_t NArgs = 16;
constexpr std::size_t ThreadCount = 4;
constexpr std::size_t LaunchCount = 8;
auto TestLambda = [&](int ThreadId) {
Queue
.submit([&](sycl::handler &CGH) {
for (std::size_t I = 0; I < NArgs; ++I)
CGH.set_arg(I, &ThreadId);
})
.wait();
};

std::vector<std::thread> threadPool;
threadPool.reserve(ThreadCount);
for (size_t tid = 0; tid < ThreadCount; ++tid) {
threadPool.push_back(std::thread(TestLambda, tid));
}

for (auto &currentThread : threadPool) {
currentThread.join();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is testing a deprecated feature, do we really need to add to the test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just combining and moving the 2 unittests SetArgForLocalAccessor and InteropKernelEnqueue to here. So, it is just keeping an existing test until this is completely deprecated and removed.

Comment on lines 36 to 58
std::cerr << "Release native context." << std::endl;
clReleaseContext(native_context);

std::cerr << "Make kernel bundle." << std::endl;
auto bundle = make_kernel_bundle<backend::opencl, bundle_state::executable>(
p, q.get_context());
std::cerr << "Release native program." << std::endl;
// cl_program must have been retained by the above call.
clReleaseProgram(p);

std::cerr << "Get native program." << std::endl;
std::vector<cl_program> device_image =
get_native<backend::opencl, bundle_state::executable>(bundle);
assert(device_image.size() == 1);
std::cerr << "Create native kernel." << std::endl;
cl_kernel k = clCreateKernel(device_image.front(), "do_nothing", nullptr);
// get_native must have retained cl_program as well.
clReleaseProgram(device_image.front());

std::cerr << "Make kernel." << std::endl;
make_kernel<backend::opencl>(k, q.get_context());
std::cerr << "Release native kernel." << std::endl;
clReleaseKernel(k);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not at all sure about removing these release calls. What's the justification for doing so?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The context is not owned by the program but was created by sycl-rt initially and the test only retrieved it with get_native so, it shouldn't releasing it as sycl-rt is responsible for that release. the program and kernel was created by the test so I have added the release calls for them back.

@omarahmed1111 omarahmed1111 force-pushed the Testing-adding-handles-to-opencl branch from 5b170a6 to 21e7aa7 Compare November 7, 2024 13:58
@omarahmed1111 omarahmed1111 force-pushed the Testing-adding-handles-to-opencl branch from 21e7aa7 to 41e1826 Compare November 7, 2024 14:12
@kbenzie kbenzie self-assigned this Nov 8, 2024
@omarahmed1111 omarahmed1111 force-pushed the Testing-adding-handles-to-opencl branch from 41e1826 to 51cef66 Compare November 18, 2024 12:48
@omarahmed1111 omarahmed1111 marked this pull request as ready for review November 18, 2024 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants