Skip to content

Commit e0f0559

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

File tree

6 files changed

+50
-23
lines changed

6 files changed

+50
-23
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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,12 @@ static bool read_hostpipe_mappings(
660660
read_uint_counters(config_str, curr_pos, mapping.pipe_width,
661661
counters) &&
662662
read_uint_counters(config_str, curr_pos, mapping.pipe_depth, counters);
663+
664+
// Start from 2024.0, there is a new field called protocol in the auto-discovery string
665+
if (result && counters.back() > 0) {
666+
result = result && read_int_counters(config_str, curr_pos,
667+
mapping.protocol, counters);
668+
}
663669

664670
hostpipe_mappings.emplace_back(mapping);
665671

src/acl_hostch.cpp

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -734,23 +734,25 @@ 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 requirs reading/writing to ready&valid signals
739+
if (host_pipe_info.protocol == 3){
740+
// If Blocking, wait until the data is valid.
741+
// If Non-blocking, just read once and report failure if not valid.
742+
do {
743+
acl_get_hal()->read_csr(host_pipe_info.m_physical_device_id, valid_reg,
744+
(void *)valid_value_pointer,
745+
(size_t)sizeof(uintptr_t));
746+
} while (blocking && valid_value != 1);
746747

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;
748+
// If non-blocking and valid bit is not set, set the op to fail.
749+
if (!blocking && valid_value == 0) {
750+
acl_mutex_unlock(&(host_pipe_info.m_lock));
751+
acl_set_device_op_execution_status(op, -1);
752+
return;
753+
}
752754
}
753-
755+
// start the CSR read
754756
auto status =
755757
acl_get_hal()->read_csr(host_pipe_info.m_physical_device_id, data_reg,
756758
event->cmd.info.host_pipe_info.ptr,
@@ -761,8 +763,11 @@ void acl_read_program_hostpipe(void *user_data, acl_device_op_t *op) {
761763
return;
762764
}
763765
// 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));
766+
// Same reason as above, only avalon_mm_uses_ready needs to do this.
767+
if (host_pipe_info.protocol == 3){
768+
acl_get_hal()->write_csr(host_pipe_info.m_physical_device_id, ready_reg,
769+
(void *)&ready, (size_t)sizeof(uintptr_t));
770+
}
766771
} else {
767772
// Non CSR Case
768773
pulled_data = acl_get_hal()->hostchannel_pull(
@@ -845,7 +850,8 @@ void acl_write_program_hostpipe(void *user_data, acl_device_op_t *op) {
845850
}
846851

847852
// In non-blocking case, there is no need to write into valid register.
848-
if (blocking) {
853+
// We only cars about valid register if the protocol is avalon_mm_uses_ready.
854+
if (blocking && host_pipe_info.protocol == 3) {
849855
// Tell CSR it's valid
850856
acl_get_hal()->write_csr(host_pipe_info.m_physical_device_id, valid_reg,
851857
(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: 6 additions & 5 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 "
1495+
"0 0 0 0 0 1 5 9 pipe_logical_name1 pipe_physical_name1 1 12345 0 1 4 10 0 "
1496+
"pipe_logical_name2 pipe_physical_name2 0 12323 1 0 8 20 1 "
14971497
"pipe_logical_name3 "
1498-
"pipe_physical_name1 1 12313 0 1 4 10 pipe_logical_name5 "
1498+
"pipe_physical_name1 1 12313 0 1 4 10 2 pipe_logical_name5 "
14991499
"pipe_physical_name1 0 "
1500-
"12316 1 0 8 20 pipe_logical_name4 pipe_physical_name3 0 12342 0 1 4 10 "
1500+
"12316 1 0 8 20 3 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");

0 commit comments

Comments
 (0)