Skip to content

Commit 8d232ae

Browse files
author
Steffen Larsen
committed
[SYCL][CUDA] Implements the program kernel names query
Signed-off-by: Steffen Larsen <[email protected]>
1 parent fc03fda commit 8d232ae

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

sycl/plugins/cuda/pi_cuda.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
#include <CL/sycl/backend/cuda.hpp>
1010
#include <CL/sycl/detail/pi.hpp>
1111
#include <pi_cuda.hpp>
12+
1213
#include <algorithm>
1314
#include <cassert>
1415
#include <cuda.h>
1516
#include <cuda_device_runtime_api.h>
16-
#include <memory>
1717
#include <limits>
18+
#include <memory>
1819
#include <mutex>
20+
#include <regex>
1921

2022
std::string getCudaVersionString() {
2123
int driver_version = 0;
@@ -447,6 +449,28 @@ pi_result getInfo<const char *>(size_t param_value_size, void *param_value,
447449
param_value_size_ret, value);
448450
}
449451

452+
/// Finds kernel names by searching for entry points in the PTX source, as the
453+
/// CUDA driver API doesn't expose an operation for this.
454+
/// Note: This is currently only being used by the SYCL program class for the
455+
/// has_kernel method, so an alternative would be to move the has_kernel
456+
/// query to PI and use cuModuleGetFunction to check for a kernel.
457+
std::string getKernelNames(pi_program program) {
458+
std::string source(program->source_,
459+
program->source_ + program->sourceLength_);
460+
std::regex entries_pattern(".entry\\s+([^\\([:s:]]*)");
461+
std::string names("");
462+
std::smatch match;
463+
bool first_match = true;
464+
while (std::regex_search(source, match, entries_pattern)) {
465+
assert(match.size() == 2);
466+
names += first_match ? "" : ";";
467+
names += match[1]; // Second element is the group.
468+
source = match.suffix().str();
469+
first_match = false;
470+
}
471+
return names;
472+
}
473+
450474
/// RAII object that calls the reference count release function on the held PI
451475
/// object on destruction.
452476
///
@@ -1993,7 +2017,7 @@ pi_result cuda_piProgramGetInfo(pi_program program, pi_program_info param_name,
19932017
&program->source_);
19942018
case PI_PROGRAM_INFO_KERNEL_NAMES: {
19952019
return getInfo(param_value_size, param_value, param_value_size_ret,
1996-
"not implemented");
2020+
getKernelNames(program).c_str());
19972021
}
19982022
default:
19992023
PI_HANDLE_UNKNOWN_PARAM_NAME(param_name);

sycl/test/basic_tests/kernel_info.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ int main() {
3333
program prg(q.get_context());
3434

3535
prg.build_with_kernel_type<class SingleTask>();
36+
CHECK(prg.has_kernel<class SingleTask>());
3637
kernel krn = prg.get_kernel<class SingleTask>();
3738

3839
q.submit([&](handler &cgh) {

0 commit comments

Comments
 (0)