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

[SYCL][CUDA] Implements the program kernel names query #1248

Merged
merged 1 commit into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
28 changes: 26 additions & 2 deletions sycl/plugins/cuda/pi_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:]]*)");
steffenlarsen marked this conversation as resolved.
Show resolved Hide resolved
std::string names("");
Copy link
Contributor

Choose a reason for hiding this comment

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

Be lazy:

std::string names;

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.
///
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions sycl/test/basic_tests/kernel_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ int main() {
program prg(q.get_context());

prg.build_with_kernel_type<class SingleTask>();
CHECK(prg.has_kernel<class SingleTask>());
kernel krn = prg.get_kernel<class SingleTask>();

q.submit([&](handler &cgh) {
Expand Down