From 68ec4854f45a4b5c02f4efab0d3112446e8bd88d Mon Sep 17 00:00:00 2001 From: Peter Colberg Date: Mon, 4 Jul 2022 17:11:38 -0400 Subject: [PATCH 1/2] auto_configure: parse streaming kernel control signal names Signed-off-by: Peter Colberg --- include/acl.h | 7 +++++++ src/acl_auto_configure.cpp | 20 ++++++++++++++------ test/acl_auto_configure_test.cpp | 27 +++++++++++++++++++++------ 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/include/acl.h b/include/acl.h index 5f191ad9..7895e772 100644 --- a/include/acl.h +++ b/include/acl.h @@ -199,6 +199,12 @@ typedef struct { std::string format_string; } acl_printf_info_t; +// Signal names for streaming control kernel. +struct acl_streaming_kernel_control_info { + std::string start; + std::string done; +}; + /* The definition of a single accelerator. * It can run a single kernel type. * We assume binary compilation only. @@ -241,6 +247,7 @@ typedef struct { unsigned int is_sycl_compile; /* [1] SYCL compile; [0] OpenCL compile*/ bool streaming_control_info_available; + acl_streaming_kernel_control_info streaming_control_info; } acl_accel_def_t; /* An ACL system definition. diff --git a/src/acl_auto_configure.cpp b/src/acl_auto_configure.cpp index a682b5f5..3fb3f7e4 100644 --- a/src/acl_auto_configure.cpp +++ b/src/acl_auto_configure.cpp @@ -663,15 +663,23 @@ static bool read_kernel_args(const std::string &config_str, return result; } -static bool -read_streaming_kernel_control_info(const std::string &config_str, - std::string::size_type &curr_pos, - bool &streaming_control_info_available, - std::vector &counters) noexcept { +static bool read_streaming_kernel_control_info( + const std::string &config_str, std::string::size_type &curr_pos, + bool &streaming_control_info_available, + acl_streaming_kernel_control_info &streaming_control_info, + std::vector &counters) noexcept { unsigned int value = 0; bool result = read_uint_counters(config_str, curr_pos, value, counters); streaming_control_info_available = value; + if (result && streaming_control_info_available) { + streaming_control_info = acl_streaming_kernel_control_info{}; + result = read_string_counters(config_str, curr_pos, + streaming_control_info.start, counters); + result = read_string_counters(config_str, curr_pos, + streaming_control_info.done, counters); + } + return result; } @@ -915,7 +923,7 @@ static bool read_accel_defs(const std::string &config_str, if (result && counters.back() > 0) { result = read_streaming_kernel_control_info( config_str, curr_pos, accel[i].streaming_control_info_available, - counters); + accel[i].streaming_control_info, counters); } // forward compatibility: bypassing remaining fields at the end of kernel diff --git a/test/acl_auto_configure_test.cpp b/test/acl_auto_configure_test.cpp index 93668b54..cf924dc9 100644 --- a/test/acl_auto_configure_test.cpp +++ b/test/acl_auto_configure_test.cpp @@ -1232,11 +1232,12 @@ TEST(auto_configure, streaming) { const std::string config_str{ "23 26 " RANDOM_HASH " pac_a10 0 1 13 DDR 2 2 24 1 2 0 4294967296 4294967296 8589934592 0 - 0 " - "0 0 0 1 3 device_global_name 256 128 1 103 _ZTS3CRCILi0EE 0 256 1 0 0 1 " + "0 0 0 1 3 device_global_name 256 128 1 105 _ZTS3CRCILi0EE 0 256 1 0 0 1 " "0 1 0 9 8 0 0 8 1 0 0 1 k0_ZTS3CRCILi0EE_arg0 8 2 1 8 1024 0 3 1 " "k0_ZTS3CRCILi0EE_arg1 8 0 0 8 1 0 0 1 k0_ZTS3CRCILi0EE_arg2 7 0 0 8 1 0 " "0 0 7 0 0 8 1 0 0 0 7 2 1 8 1024 0 2 0 7 0 0 8 1 0 0 0 7 0 0 8 1 0 0 0 " - "7 0 0 8 1 0 0 0 0 0 1 2 64 4096 1 1 1 3 1 1 1 3 1 0 1"}; + "7 0 0 8 1 0 0 0 0 0 1 2 64 4096 1 1 1 3 1 1 1 3 1 0 1 " + "k0_ZTS3CRCILi0EE_streaming_start k0_ZTS3CRCILi0EE_streaming_done "}; acl_device_def_autodiscovery_t devdef; { @@ -1252,6 +1253,10 @@ TEST(auto_configure, streaming) { CHECK(!devdef.accel[0].is_sycl_compile); CHECK(devdef.accel[0].streaming_control_info_available); + CHECK("k0_ZTS3CRCILi0EE_streaming_start" == + devdef.accel[0].streaming_control_info.start); + CHECK("k0_ZTS3CRCILi0EE_streaming_done" == + devdef.accel[0].streaming_control_info.done); const auto &args = devdef.accel[0].iface.args; CHECK_EQUAL(9, args.size()); @@ -1274,13 +1279,14 @@ TEST(auto_configure, one_streaming_arg_and_streaming_kernel) { const std::string config_str{ "23 27 531091a097f0d7096b21f349b4b283f9e206ebc0 pac_s10 0 1 17 DDR 2 4 " "24 1 2 0 8589934592 8589934592 17179869184 17179869184 25769803776 " - "25769803776 34359738368 0 - 0 0 0 0 0 0 1 123 _ZTS15binomial_kernel 0 " + "25769803776 34359738368 0 - 0 0 0 0 0 0 1 125 _ZTS15binomial_kernel 0 " "256 0 0 0 0 0 1 0 8 7 2 1 8 1024 0 2 0 8 0 0 8 1 0 0 1 " "k0_ZTS15binomial_kernel_arg1 7 0 0 8 1 0 0 0 7 0 0 8 1 0 0 0 7 2 1 8 " "1024 0 2 0 7 0 0 8 1 0 0 0 7 0 0 8 1 0 0 0 7 0 0 8 1 0 0 0 0 0 16 2 64 " "8196 65 8196 66 8196 67 8196 68 8196 69 8196 70 8196 71 8196 72 8196 73 " "8196 74 8196 75 8196 76 8196 77 8196 78 8196 79 8196 1 1 1 3 1 1 1 3 1 " - "1 1"}; + "1 1 k0_ZTS15binomial_kernel_streaming_start " + "k0_ZTS15binomial_kernel_streaming_done "}; acl_device_def_autodiscovery_t devdef; { @@ -1295,6 +1301,10 @@ TEST(auto_configure, one_streaming_arg_and_streaming_kernel) { CHECK_EQUAL(1, devdef.accel.size()); CHECK(devdef.accel[0].streaming_control_info_available); + CHECK("k0_ZTS15binomial_kernel_streaming_start" == + devdef.accel[0].streaming_control_info.start); + CHECK("k0_ZTS15binomial_kernel_streaming_done" == + devdef.accel[0].streaming_control_info.done); const auto &args = devdef.accel[0].iface.args; CHECK_EQUAL(8, args.size()); @@ -1314,13 +1324,14 @@ TEST(auto_configure, two_streaming_args_and_streaming_kernel) { const std::string config_str{ "23 27 531091a097f0d7096b21f349b4b283f9e206ebc0 pac_s10 0 1 17 DDR 2 4 " "24 1 2 0 8589934592 8589934592 17179869184 17179869184 25769803776 " - "25769803776 34359738368 0 - 0 0 0 0 0 0 1 124 _ZTS15binomial_kernel 0 " + "25769803776 34359738368 0 - 0 0 0 0 0 0 1 126 _ZTS15binomial_kernel 0 " "256 0 0 0 0 0 1 0 8 8 2 1 8 1024 0 2 1 k0_ZTS15binomial_kernel_arg0 8 0 " "0 8 1 0 0 1 k0_ZTS15binomial_kernel_arg1 7 0 0 8 1 0 0 0 7 0 0 8 1 0 0 " "0 7 2 1 8 1024 0 2 0 7 0 0 8 1 0 0 0 7 0 0 8 1 0 0 0 7 0 0 8 1 0 0 0 0 " "0 16 2 64 8196 65 8196 66 8196 67 8196 68 8196 69 8196 70 8196 71 8196 " "72 8196 73 8196 74 8196 75 8196 76 8196 77 8196 78 8196 79 8196 1 1 1 3 " - "1 1 1 3 1 1 1"}; + "1 1 1 3 1 1 1 k0_ZTS15binomial_kernel_streaming_start " + "k0_ZTS15binomial_kernel_streaming_done "}; acl_device_def_autodiscovery_t devdef; { @@ -1336,6 +1347,10 @@ TEST(auto_configure, two_streaming_args_and_streaming_kernel) { CHECK(devdef.accel[0].is_sycl_compile); CHECK(devdef.accel[0].streaming_control_info_available); + CHECK("k0_ZTS15binomial_kernel_streaming_start" == + devdef.accel[0].streaming_control_info.start); + CHECK("k0_ZTS15binomial_kernel_streaming_done" == + devdef.accel[0].streaming_control_info.done); const auto &args = devdef.accel[0].iface.args; CHECK_EQUAL(8, args.size()); From cd2750421d6794a9f3b2dc2935ad182c8cbf94e0 Mon Sep 17 00:00:00 2001 From: Peter Colberg Date: Mon, 4 Jul 2022 17:33:00 -0400 Subject: [PATCH 2/2] kernel_if: pass streaming control signal names to simulator For the case of streaming control kernels in IP authoring, when passing the start and done signals to the simulator MMD, instead of the kernel interface name, pass the full signal names from the auto-discovery string. Before this change, the runtime would pass the kernel name, e.g., `_ZTSZ4mainE4MyIP` without the prefix including the kernel index in case of multiple kernels. After this change, the runtime passes the full signal names, e.g., `k0_ZTSZ4mainE4MyIP_streaming_start` including the kernel index prefix and the streaming control signal suffix. This amends https://github.com/intel/fpga-runtime-for-opencl/pull/103 Signed-off-by: Peter Colberg --- include/acl_hal.h | 4 ++-- include/acl_hal_mmd.h | 4 ++-- include/acl_kernel_if.h | 3 ++- src/acl_kernel_if.cpp | 20 ++++++++++---------- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/include/acl_hal.h b/include/acl_hal.h index b54767a2..5c51373c 100644 --- a/include/acl_hal.h +++ b/include/acl_hal.h @@ -241,9 +241,9 @@ typedef struct { mem_properties_t *properties, int *error); void (*simulation_streaming_kernel_start)(unsigned int physical_device_id, - const std::string &kernel_name); + const std::string &signal_name); void (*simulation_streaming_kernel_done)(unsigned int physical_device_id, - const std::string &kernel_name, + const std::string &signal_name, unsigned int &finish_counter); } acl_hal_t; diff --git a/include/acl_hal_mmd.h b/include/acl_hal_mmd.h index beadd7fd..1049e85f 100644 --- a/include/acl_hal_mmd.h +++ b/include/acl_hal_mmd.h @@ -139,7 +139,7 @@ typedef struct { // Submits streaming kernel control start signal to simulator. void (*aocl_mmd_simulation_streaming_kernel_start)( - int handle, const std::string &kernel_name); + int handle, const std::string &signal_name); // Queries streaming kernel control done signal from simulator. // Returns non-negative number of finished kernels invocations. @@ -148,7 +148,7 @@ typedef struct { // invocations that finish *while* this function is invoked are properly // accounted and returned in a subsequent invocation of this function. void (*aocl_mmd_simulation_streaming_kernel_done)( - int handle, const std::string &kernel_name, unsigned int &finish_counter); + int handle, const std::string &signal_name, unsigned int &finish_counter); } acl_mmd_dispatch_t; typedef struct { diff --git a/include/acl_kernel_if.h b/include/acl_kernel_if.h index 51ddcf8b..7e3b0d72 100644 --- a/include/acl_kernel_if.h +++ b/include/acl_kernel_if.h @@ -39,7 +39,8 @@ typedef struct { acl_kernel_if_addr_range *accel_perf_mon; unsigned int *accel_num_printfs; - std::vector> streaming_control_kernel_names; + std::vector> + streaming_control_signal_names; // Track potential hangs time_ns last_kern_update; diff --git a/src/acl_kernel_if.cpp b/src/acl_kernel_if.cpp index 06fd80f8..7a5f7bf6 100644 --- a/src/acl_kernel_if.cpp +++ b/src/acl_kernel_if.cpp @@ -949,14 +949,14 @@ int acl_kernel_if_update(const acl_device_def_autodiscovery_t &devdef, } } - kern->streaming_control_kernel_names.clear(); - kern->streaming_control_kernel_names.reserve(devdef.accel.size()); + kern->streaming_control_signal_names.clear(); + kern->streaming_control_signal_names.reserve(devdef.accel.size()); for (const auto &accel : devdef.accel) { - std::optional kernel_name; + std::optional signal_names; if (accel.streaming_control_info_available) { - kernel_name = accel.iface.name; + signal_names = accel.streaming_control_info; } - kern->streaming_control_kernel_names.emplace_back(kernel_name); + kern->streaming_control_signal_names.emplace_back(signal_names); } } @@ -1266,10 +1266,10 @@ void acl_kernel_if_launch_kernel_on_custom_sof( } kern->accel_queue_front[accel_id] = next_launch_index; - if (kern->streaming_control_kernel_names[accel_id]) { + if (kern->streaming_control_signal_names[accel_id]) { acl_get_hal()->simulation_streaming_kernel_start( kern->physical_device_id, - *kern->streaming_control_kernel_names[accel_id]); + kern->streaming_control_signal_names[accel_id]->start); return; } @@ -1510,10 +1510,10 @@ void acl_kernel_if_update_status(acl_kernel_if *kern) { unsigned int finish_counter = 0; unsigned int printf_size = 0; - if (kern->streaming_control_kernel_names[accel_id]) { + if (kern->streaming_control_signal_names[accel_id]) { acl_get_hal()->simulation_streaming_kernel_done( kern->physical_device_id, - *kern->streaming_control_kernel_names[accel_id], finish_counter); + kern->streaming_control_signal_names[accel_id]->done, finish_counter); } else { acl_kernel_if_update_status_query(kern, accel_id, activation_id, finish_counter, printf_size); @@ -1531,7 +1531,7 @@ void acl_kernel_if_update_status(acl_kernel_if *kern) { // Tell the host library this job is done kern->accel_job_ids[accel_id][next_queue_back] = -1; - if (!kern->streaming_control_kernel_names[accel_id]) { + if (!kern->streaming_control_signal_names[accel_id]) { acl_kernel_if_update_status_finish(kern, accel_id, activation_id, printf_size); }