|
9 | 9 | #include <CL/sycl/backend/cuda.hpp>
|
10 | 10 | #include <CL/sycl/detail/pi.hpp>
|
11 | 11 | #include <pi_cuda.hpp>
|
| 12 | + |
12 | 13 | #include <algorithm>
|
13 | 14 | #include <cassert>
|
14 | 15 | #include <cuda.h>
|
15 | 16 | #include <cuda_device_runtime_api.h>
|
16 |
| -#include <memory> |
17 | 17 | #include <limits>
|
| 18 | +#include <memory> |
18 | 19 | #include <mutex>
|
| 20 | +#include <regex> |
19 | 21 |
|
20 | 22 | std::string getCudaVersionString() {
|
21 | 23 | int driver_version = 0;
|
@@ -447,6 +449,28 @@ pi_result getInfo<const char *>(size_t param_value_size, void *param_value,
|
447 | 449 | param_value_size_ret, value);
|
448 | 450 | }
|
449 | 451 |
|
| 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 | + |
450 | 474 | /// RAII object that calls the reference count release function on the held PI
|
451 | 475 | /// object on destruction.
|
452 | 476 | ///
|
@@ -1993,7 +2017,7 @@ pi_result cuda_piProgramGetInfo(pi_program program, pi_program_info param_name,
|
1993 | 2017 | &program->source_);
|
1994 | 2018 | case PI_PROGRAM_INFO_KERNEL_NAMES: {
|
1995 | 2019 | return getInfo(param_value_size, param_value, param_value_size_ret,
|
1996 |
| - "not implemented"); |
| 2020 | + getKernelNames(program).c_str()); |
1997 | 2021 | }
|
1998 | 2022 | default:
|
1999 | 2023 | PI_HANDLE_UNKNOWN_PARAM_NAME(param_name);
|
|
0 commit comments