-
Notifications
You must be signed in to change notification settings - Fork 788
[SYCL][CUDA] Implements the program kernel names query #1248
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,13 +9,15 @@ | |
#include <CL/sycl/backend/cuda.hpp> | ||
#include <CL/sycl/detail/pi.hpp> | ||
#include <pi_cuda.hpp> | ||
|
||
#include <algorithm> | ||
#include <cassert> | ||
#include <cuda.h> | ||
#include <cuda_device_runtime_api.h> | ||
#include <memory> | ||
#include <limits> | ||
#include <memory> | ||
#include <mutex> | ||
#include <regex> | ||
|
||
std::string getCudaVersionString() { | ||
int driver_version = 0; | ||
|
@@ -447,6 +449,28 @@ pi_result getInfo<const char *>(size_t param_value_size, void *param_value, | |
param_value_size_ret, value); | ||
} | ||
|
||
/// Finds kernel names by searching for entry points in the PTX source, as the | ||
/// CUDA driver API doesn't expose an operation for this. | ||
/// Note: This is currently only being used by the SYCL program class for the | ||
/// has_kernel method, so an alternative would be to move the has_kernel | ||
/// query to PI and use cuModuleGetFunction to check for a kernel. | ||
std::string getKernelNames(pi_program program) { | ||
std::string source(program->source_, | ||
program->source_ + program->sourceLength_); | ||
std::regex entries_pattern(".entry\\s+([^\\([:s:]]*)"); | ||
std::string names(""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Be lazy:
|
||
std::smatch match; | ||
steffenlarsen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
bool first_match = true; | ||
while (std::regex_search(source, match, entries_pattern)) { | ||
assert(match.size() == 2); | ||
names += first_match ? "" : ";"; | ||
names += match[1]; // Second element is the group. | ||
source = match.suffix().str(); | ||
first_match = false; | ||
} | ||
return names; | ||
} | ||
|
||
/// RAII object that calls the reference count release function on the held PI | ||
/// object on destruction. | ||
/// | ||
|
@@ -1993,7 +2017,7 @@ pi_result cuda_piProgramGetInfo(pi_program program, pi_program_info param_name, | |
&program->source_); | ||
case PI_PROGRAM_INFO_KERNEL_NAMES: { | ||
return getInfo(param_value_size, param_value, param_value_size_ret, | ||
"not implemented"); | ||
getKernelNames(program).c_str()); | ||
} | ||
default: | ||
PI_HANDLE_UNKNOWN_PARAM_NAME(param_name); | ||
|
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
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.