Skip to content

Commit c9f7cfd

Browse files
committed
Parse streaming kernel information from auto-discovery string
Signed-off-by: Peter Colberg <peter.colberg@intel.com>
1 parent d10fef0 commit c9f7cfd

File tree

3 files changed

+137
-0
lines changed

3 files changed

+137
-0
lines changed

include/acl.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <array>
88
#include <assert.h>
9+
#include <optional>
910
#include <string>
1011
#include <unordered_map>
1112
#include <vector>
@@ -136,6 +137,11 @@ typedef enum {
136137
} acl_kernel_arg_access_qualifier_t; // this is defaulted to none, for non-pipe
137138
// and non-image args.
138139

140+
struct acl_streaming_kernel_arg_info {
141+
// name of the streaming interface at device image boundary
142+
std::string interface_name;
143+
};
144+
139145
// This defines everything "interface" of a kernel argument.
140146
// Be sure to keep this consistent with l_kernel_interface_match() in
141147
// acl_kernel.cpp. This struct must remain trivially copyable.
@@ -170,6 +176,8 @@ typedef struct {
170176
// allowed, e.g., "struct mystruct"
171177
std::string type_name;
172178
std::string name;
179+
180+
std::optional<acl_streaming_kernel_arg_info> streaming_info;
173181
} acl_kernel_arg_info_t;
174182

175183
// This struct must remain trivially copyable.
@@ -191,6 +199,13 @@ typedef struct {
191199
std::string format_string;
192200
} acl_printf_info_t;
193201

202+
struct acl_streaming_kernel_info {
203+
std::string start;
204+
std::string done;
205+
std::string stall_in;
206+
std::string stall_out;
207+
};
208+
194209
/* The definition of a single accelerator.
195210
* It can run a single kernel type.
196211
* We assume binary compilation only.
@@ -231,6 +246,8 @@ typedef struct {
231246
fast_launch_depth; /* How many kernels can be buffered on the device, 0
232247
means no buffering just one can execute*/
233248
unsigned int is_sycl_compile; /* [1] SYCL compile; [0] OpenCL compile*/
249+
250+
std::optional<acl_streaming_kernel_info> streaming_info;
234251
} acl_accel_def_t;
235252

236253
/* An ACL system definition.

src/acl_auto_configure.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,30 @@ static bool read_device_global_mem_defs(
504504
return result;
505505
}
506506

507+
static bool read_streaming_kernel_arg_info(
508+
const std::string &config_str, std::string::size_type &curr_pos,
509+
std::optional<acl_streaming_kernel_arg_info> &streaming_info,
510+
std::vector<int> &counters) noexcept {
511+
int num_fields = 0;
512+
bool result = read_int_counters(config_str, curr_pos, num_fields, counters);
513+
counters.emplace_back(num_fields);
514+
515+
if (result && counters.back() > 0) {
516+
streaming_info = std::make_optional(acl_streaming_kernel_arg_info{});
517+
result = read_string_counters(config_str, curr_pos,
518+
streaming_info->interface_name, counters);
519+
}
520+
521+
while (result && counters.back() > 0) {
522+
std::string tmp;
523+
result = read_string_counters(config_str, curr_pos, tmp, counters);
524+
}
525+
check_section_counters(counters);
526+
counters.pop_back();
527+
528+
return result;
529+
}
530+
507531
static bool read_kernel_args(const std::string &config_str,
508532
const bool kernel_arg_info_available,
509533
std::string::size_type &curr_pos,
@@ -597,6 +621,12 @@ static bool read_kernel_args(const std::string &config_str,
597621
type_name = "";
598622
}
599623

624+
std::optional<acl_streaming_kernel_arg_info> streaming_info;
625+
if (result && counters.back() > 0) {
626+
result = read_streaming_kernel_arg_info(config_str, curr_pos,
627+
streaming_info, counters);
628+
}
629+
600630
/*****************************************************************
601631
Since the introduction of autodiscovery forwards-compatibility,
602632
new entries for each kernel argument section start here.
@@ -619,6 +649,7 @@ static bool read_kernel_args(const std::string &config_str,
619649
args[j].host_accessible = host_accessible;
620650
args[j].pipe_channel_id = pipe_channel_id;
621651
args[j].buffer_location = buffer_location;
652+
args[j].streaming_info = streaming_info;
622653
}
623654
// forward compatibility: bypassing remaining fields at the end of
624655
// arguments section
@@ -635,6 +666,36 @@ static bool read_kernel_args(const std::string &config_str,
635666
return result;
636667
}
637668

669+
static bool read_streaming_kernel_info(
670+
const std::string &config_str, std::string::size_type &curr_pos,
671+
std::optional<acl_streaming_kernel_info> &streaming_info,
672+
std::vector<int> &counters) noexcept {
673+
int num_fields = 0;
674+
bool result = read_int_counters(config_str, curr_pos, num_fields, counters);
675+
counters.emplace_back(num_fields);
676+
677+
if (result && counters.back() > 0) {
678+
streaming_info = std::make_optional(acl_streaming_kernel_info{});
679+
result = read_string_counters(config_str, curr_pos, streaming_info->start,
680+
counters) &&
681+
read_string_counters(config_str, curr_pos, streaming_info->done,
682+
counters) &&
683+
read_string_counters(config_str, curr_pos,
684+
streaming_info->stall_in, counters) &&
685+
read_string_counters(config_str, curr_pos,
686+
streaming_info->stall_out, counters);
687+
}
688+
689+
while (result && counters.back() > 0) {
690+
std::string tmp;
691+
result = read_string_counters(config_str, curr_pos, tmp, counters);
692+
}
693+
check_section_counters(counters);
694+
counters.pop_back();
695+
696+
return result;
697+
}
698+
638699
static bool read_accel_defs(const std::string &config_str,
639700
std::string::size_type &curr_pos,
640701
const bool kernel_arg_info_available,
@@ -872,6 +933,11 @@ static bool read_accel_defs(const std::string &config_str,
872933
accel[i].is_sycl_compile, counters);
873934
}
874935

936+
if (result && counters.back() > 0) {
937+
result = read_streaming_kernel_info(config_str, curr_pos,
938+
accel[i].streaming_info, counters);
939+
}
940+
875941
// forward compatibility: bypassing remaining fields at the end of kernel
876942
// description section
877943
while (result && counters.size() > 0 &&

test/acl_auto_configure_test.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,3 +1227,57 @@ TEST(auto_configure, hostpipe) {
12271227
CHECK_EQUAL(1, (int)device_def.autodiscovery_def.hal_info.size());
12281228
}
12291229
}
1230+
1231+
TEST(auto_configure, streaming) {
1232+
const std::string config_str{
1233+
"23 26 " RANDOM_HASH
1234+
" pac_a10 0 1 13 DDR 2 2 24 1 2 0 4294967296 4294967296 8589934592 0 - 0 "
1235+
"0 0 0 1 3 device_global_name 256 128 1 107 _ZTS3CRCILi0EE 0 256 1 0 0 1 "
1236+
"0 1 0 9 8 0 0 8 1 0 0 1 k0_ZTS3CRCILi0EE_arg0 8 2 1 8 1024 0 3 1 "
1237+
"k0_ZTS3CRCILi0EE_arg1 8 0 0 8 1 0 0 1 k0_ZTS3CRCILi0EE_arg2 7 0 0 8 1 0 "
1238+
"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 "
1239+
"7 0 0 8 1 0 0 0 0 0 1 2 64 4096 1 1 1 3 1 1 1 3 1 0 4 "
1240+
"k0_ZTS3CRCILi0EE_streaming_start k0_ZTS3CRCILi0EE_streaming_done "
1241+
"k0_ZTS3CRCILi0EE_streaming_stall_in "
1242+
"k0_ZTS3CRCILi0EE_streaming_stall_out"};
1243+
1244+
acl_device_def_autodiscovery_t devdef;
1245+
{
1246+
bool result;
1247+
std::string err_str;
1248+
ACL_LOCKED(result =
1249+
acl_load_device_def_from_str(config_str, devdef, err_str));
1250+
std::cerr << err_str;
1251+
CHECK(result);
1252+
}
1253+
1254+
CHECK_EQUAL(1, devdef.accel.size());
1255+
1256+
CHECK(!!devdef.accel[0].streaming_info);
1257+
CHECK("k0_ZTS3CRCILi0EE_streaming_start" ==
1258+
devdef.accel[0].streaming_info->start);
1259+
CHECK("k0_ZTS3CRCILi0EE_streaming_done" ==
1260+
devdef.accel[0].streaming_info->done);
1261+
CHECK("k0_ZTS3CRCILi0EE_streaming_stall_in" ==
1262+
devdef.accel[0].streaming_info->stall_in);
1263+
CHECK("k0_ZTS3CRCILi0EE_streaming_stall_out" ==
1264+
devdef.accel[0].streaming_info->stall_out);
1265+
1266+
CHECK_EQUAL(9, devdef.accel[0].iface.args.size());
1267+
1268+
CHECK(!!devdef.accel[0].iface.args[0].streaming_info);
1269+
CHECK("k0_ZTS3CRCILi0EE_arg0" ==
1270+
devdef.accel[0].iface.args[0].streaming_info->interface_name);
1271+
1272+
CHECK(!!devdef.accel[0].iface.args[1].streaming_info);
1273+
CHECK("k0_ZTS3CRCILi0EE_arg1" ==
1274+
devdef.accel[0].iface.args[1].streaming_info->interface_name);
1275+
1276+
CHECK(!!devdef.accel[0].iface.args[2].streaming_info);
1277+
CHECK("k0_ZTS3CRCILi0EE_arg2" ==
1278+
devdef.accel[0].iface.args[2].streaming_info->interface_name);
1279+
1280+
for (size_t i = 3; i < 9; ++i) {
1281+
CHECK(!devdef.accel[0].iface.args[i].streaming_info);
1282+
}
1283+
}

0 commit comments

Comments
 (0)