Skip to content

Commit 1b6d4aa

Browse files
committed
Support AVALON_MM CSR hostpipe
1 parent a82f940 commit 1b6d4aa

File tree

6 files changed

+59
-25
lines changed

6 files changed

+59
-25
lines changed

include/acl.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,13 @@ struct acl_hostpipe_mapping {
535535
bool is_write;
536536
unsigned pipe_width;
537537
unsigned pipe_depth;
538+
539+
// Matches the protocol_name enum in
540+
// https://github.com/intel/llvm/blob/sycl/sycl/include/sycl/ext/intel/experimental/pipe_properties.hpp
541+
// Set a default value in case it's missing.
542+
543+
int protocol = -1; // avalon_streaming = 0, avalon_streaming_uses_ready = 1
544+
// avalon_mm = 2, avalon_mm_uses_ready = 3
538545
};
539546

540547
// Part of acl_device_def_t where members are populated from the information

include/acl_types.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,12 @@ typedef struct host_pipe_struct {
331331
// non-CSR program hostpipe
332332
std::string csr_address;
333333

334+
// Matches the protocol_name enum in
335+
// https://github.com/intel/llvm/blob/sycl/sycl/include/sycl/ext/intel/experimental/pipe_properties.hpp
336+
// Set a default value in case it's missing.
337+
int protocol = -1; // avalon_streaming = 0, avalon_streaming_uses_ready = 1
338+
// avalon_mm = 2, avalon_mm_uses_ready = 3
339+
334340
} host_pipe_t;
335341

336342
// The device-specific information about a program.

src/acl_auto_configure.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,13 @@ static bool read_hostpipe_mappings(
661661
counters) &&
662662
read_uint_counters(config_str, curr_pos, mapping.pipe_depth, counters);
663663

664+
// Start from 2024.0, there is a new field called protocol in the
665+
// auto-discovery string
666+
if (result && counters.back() > 0) {
667+
result = result && read_int_counters(config_str, curr_pos,
668+
mapping.protocol, counters);
669+
}
670+
664671
hostpipe_mappings.emplace_back(mapping);
665672

666673
while (result && counters.back() > 0) {

src/acl_hostch.cpp

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -734,23 +734,26 @@ void acl_read_program_hostpipe(void *user_data, acl_device_op_t *op) {
734734
unsigned valid_value;
735735
unsigned *valid_value_pointer = &valid_value;
736736

737-
// start the CSR read
738-
739-
// If Blocking, wait until the data is valid.
740-
// If Non-blocking, just read once and report failure if not valid.
741-
do {
742-
acl_get_hal()->read_csr(host_pipe_info.m_physical_device_id, valid_reg,
743-
(void *)valid_value_pointer,
744-
(size_t)sizeof(uintptr_t));
745-
} while (blocking && valid_value != 1);
737+
// protocol 3 is the avalon_mm_uses_ready protocol
738+
// Only this uses_ready protocol requires reading/writing to ready&valid
739+
// signals
740+
if (host_pipe_info.protocol == 3) {
741+
// If Blocking, wait until the data is valid.
742+
// If Non-blocking, just read once and report failure if not valid.
743+
do {
744+
acl_get_hal()->read_csr(host_pipe_info.m_physical_device_id, valid_reg,
745+
(void *)valid_value_pointer,
746+
(size_t)sizeof(uintptr_t));
747+
} while (blocking && valid_value != 1);
746748

747-
// If non-blocking and valid bit is not set, set the op to fail.
748-
if (!blocking && valid_value == 0) {
749-
acl_mutex_unlock(&(host_pipe_info.m_lock));
750-
acl_set_device_op_execution_status(op, -1);
751-
return;
749+
// If non-blocking and valid bit is not set, set the op to fail.
750+
if (!blocking && valid_value == 0) {
751+
acl_mutex_unlock(&(host_pipe_info.m_lock));
752+
acl_set_device_op_execution_status(op, -1);
753+
return;
754+
}
752755
}
753-
756+
// start the CSR read
754757
auto status =
755758
acl_get_hal()->read_csr(host_pipe_info.m_physical_device_id, data_reg,
756759
event->cmd.info.host_pipe_info.ptr,
@@ -761,8 +764,11 @@ void acl_read_program_hostpipe(void *user_data, acl_device_op_t *op) {
761764
return;
762765
}
763766
// Tell CSR it's ready
764-
acl_get_hal()->write_csr(host_pipe_info.m_physical_device_id, ready_reg,
765-
(void *)&ready, (size_t)sizeof(uintptr_t));
767+
// Same reason as above, only avalon_mm_uses_ready needs to do this.
768+
if (host_pipe_info.protocol == 3) {
769+
acl_get_hal()->write_csr(host_pipe_info.m_physical_device_id, ready_reg,
770+
(void *)&ready, (size_t)sizeof(uintptr_t));
771+
}
766772
} else {
767773
// Non CSR Case
768774
pulled_data = acl_get_hal()->hostchannel_pull(
@@ -845,7 +851,9 @@ void acl_write_program_hostpipe(void *user_data, acl_device_op_t *op) {
845851
}
846852

847853
// In non-blocking case, there is no need to write into valid register.
848-
if (blocking) {
854+
// We only care about valid register if the protocol is
855+
// avalon_mm_uses_ready.
856+
if (blocking && host_pipe_info.protocol == 3) {
849857
// Tell CSR it's valid
850858
acl_get_hal()->write_csr(host_pipe_info.m_physical_device_id, valid_reg,
851859
(void *)&valid, (size_t)sizeof(uintptr_t));

src/acl_program.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,7 @@ l_register_hostpipes_to_program(acl_device_program_info_t *dev_prog,
13631363
return CL_INVALID_VALUE;
13641364
}
13651365
}
1366+
host_pipe_info.protocol = hostpipe.protocol;
13661367
acl_mutex_init(&(host_pipe_info.m_lock), NULL);
13671368
// The following property is not used by the program scoped hostpipe but we
13681369
// don't want to leave it uninitialized

test/acl_auto_configure_test.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,14 +1490,14 @@ TEST(auto_configure, cra_ring_root_exist) {
14901490

14911491
TEST(auto_configure, hostpipe_mappings) {
14921492
const std::string config_str{
1493-
"23 66 " RANDOM_HASH
1493+
"23 71 " RANDOM_HASH
14941494
" pac_a10 0 1 13 DDR 2 2 24 1 2 0 4294967296 4294967296 8589934592 0 - 0 "
1495-
"0 0 0 0 0 1 5 8 pipe_logical_name1 pipe_physical_name1 1 12345 0 1 4 10 "
1496-
"pipe_logical_name2 pipe_physical_name2 0 12323 1 0 8 20 "
1497-
"pipe_logical_name3 "
1498-
"pipe_physical_name1 1 12313 0 1 4 10 pipe_logical_name5 "
1499-
"pipe_physical_name1 0 "
1500-
"12316 1 0 8 20 pipe_logical_name4 pipe_physical_name3 0 12342 0 1 4 10 "
1495+
"0 0 0 0 0 1 5 9 " // 5 Hostpipes, 9 in each mapping
1496+
"pipe_logical_name1 pipe_physical_name1 1 12345 0 1 4 10 0 "
1497+
"pipe_logical_name2 pipe_physical_name2 0 12323 1 0 8 20 1 "
1498+
"pipe_logical_name3 pipe_physical_name1 1 12313 0 1 4 10 2 "
1499+
"pipe_logical_name5 pipe_physical_name1 0 12316 1 0 8 20 3 "
1500+
"pipe_logical_name4 pipe_physical_name3 0 12342 0 1 4 10 3 "
15011501
"3 90 "
15021502
"_ZTS3CRCILi0EE 512 256 1 0 0 1 0 1 0 9 6 0 0 8 1 0 0 6 2 1 8 1024 0 3 6 "
15031503
"0 0 8 1 0 0 6 0 0 8 1 0 0 6 0 0 8 1 0 0 6 2 1 8 1024 0 2 6 0 0 8 1 0 0 "
@@ -1531,6 +1531,7 @@ TEST(auto_configure, hostpipe_mappings) {
15311531
CHECK(devdef.hostpipe_mappings[0].is_write);
15321532
CHECK(devdef.hostpipe_mappings[0].pipe_width == 4);
15331533
CHECK(devdef.hostpipe_mappings[0].pipe_depth == 10);
1534+
CHECK(devdef.hostpipe_mappings[0].protocol == 0);
15341535

15351536
CHECK(devdef.hostpipe_mappings[1].logical_name == "pipe_logical_name2");
15361537
CHECK(devdef.hostpipe_mappings[1].physical_name == "pipe_physical_name2");
@@ -1540,6 +1541,7 @@ TEST(auto_configure, hostpipe_mappings) {
15401541
CHECK(!devdef.hostpipe_mappings[1].is_write);
15411542
CHECK(devdef.hostpipe_mappings[1].pipe_width == 8);
15421543
CHECK(devdef.hostpipe_mappings[1].pipe_depth == 20);
1544+
CHECK(devdef.hostpipe_mappings[1].protocol == 1);
15431545

15441546
CHECK(devdef.hostpipe_mappings[2].logical_name == "pipe_logical_name3");
15451547
CHECK(devdef.hostpipe_mappings[2].physical_name == "pipe_physical_name1");
@@ -1549,6 +1551,7 @@ TEST(auto_configure, hostpipe_mappings) {
15491551
CHECK(devdef.hostpipe_mappings[2].is_write);
15501552
CHECK(devdef.hostpipe_mappings[2].pipe_width == 4);
15511553
CHECK(devdef.hostpipe_mappings[2].pipe_depth == 10);
1554+
CHECK(devdef.hostpipe_mappings[2].protocol == 2);
15521555

15531556
CHECK(devdef.hostpipe_mappings[3].logical_name == "pipe_logical_name5");
15541557
CHECK(devdef.hostpipe_mappings[3].physical_name == "pipe_physical_name1");
@@ -1558,6 +1561,7 @@ TEST(auto_configure, hostpipe_mappings) {
15581561
CHECK(!devdef.hostpipe_mappings[3].is_write);
15591562
CHECK(devdef.hostpipe_mappings[3].pipe_width == 8);
15601563
CHECK(devdef.hostpipe_mappings[3].pipe_depth == 20);
1564+
CHECK(devdef.hostpipe_mappings[3].protocol == 3);
15611565

15621566
CHECK(devdef.hostpipe_mappings[4].logical_name == "pipe_logical_name4");
15631567
CHECK(devdef.hostpipe_mappings[4].physical_name == "pipe_physical_name3");
@@ -1567,4 +1571,5 @@ TEST(auto_configure, hostpipe_mappings) {
15671571
CHECK(devdef.hostpipe_mappings[4].is_write);
15681572
CHECK(devdef.hostpipe_mappings[4].pipe_width == 4);
15691573
CHECK(devdef.hostpipe_mappings[4].pipe_depth == 10);
1574+
CHECK(devdef.hostpipe_mappings[4].protocol == 3);
15701575
}

0 commit comments

Comments
 (0)