Skip to content

Commit 0ec67a0

Browse files
committed
Fix CSR Pipe
1 parent 011f094 commit 0ec67a0

File tree

1 file changed

+35
-9
lines changed

1 file changed

+35
-9
lines changed

src/acl_hostch.cpp

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -736,17 +736,30 @@ void acl_read_program_hostpipe(void *user_data, acl_device_op_t *op) {
736736

737737
// start the CSR read
738738

739-
// Checking if the data is valid, blocking
739+
// If Blocking, wait until the data is valid.
740+
// If Non-blocking, just read once and report failure if not valid.
740741
do {
741742
acl_get_hal()->read_csr(host_pipe_info.m_physical_device_id, valid_reg,
742743
(void *)valid_value_pointer,
743744
(size_t)sizeof(uintptr_t));
744-
} while (valid_value != 1);
745+
} while (blocking && valid_value != 1);
745746

746-
pulled_data =
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;
752+
}
753+
754+
auto status =
747755
acl_get_hal()->read_csr(host_pipe_info.m_physical_device_id, data_reg,
748756
event->cmd.info.host_pipe_info.ptr,
749757
event->cmd.info.host_pipe_info.size);
758+
if (status != 0) {
759+
acl_mutex_unlock(&(host_pipe_info.m_lock));
760+
acl_set_device_op_execution_status(op, -1);
761+
return;
762+
}
750763
// Tell CSR it's ready
751764
acl_get_hal()->write_csr(host_pipe_info.m_physical_device_id, ready_reg,
752765
(void *)&ready, (size_t)sizeof(uintptr_t));
@@ -807,7 +820,6 @@ void acl_write_program_hostpipe(void *user_data, acl_device_op_t *op) {
807820
// Get CSR address
808821
unsigned long long parsed;
809822
uintptr_t data_reg, valid_reg;
810-
size_t pushed_data;
811823
try {
812824
parsed = std::stoull(host_pipe_info.csr_address, nullptr);
813825
} catch (const std::exception &) {
@@ -821,18 +833,32 @@ void acl_write_program_hostpipe(void *user_data, acl_device_op_t *op) {
821833
// this to the autodiscovery string maybe
822834
unsigned int valid = 1;
823835
// start the write
824-
pushed_data =
836+
auto status =
825837
acl_get_hal()->write_csr(host_pipe_info.m_physical_device_id, data_reg,
826838
event->cmd.info.host_pipe_info.write_ptr,
827839
event->cmd.info.host_pipe_info.size);
828-
if (pushed_data != event->cmd.info.host_pipe_info.size) {
840+
if (status != 0) {
829841
acl_mutex_unlock(&(host_pipe_info.m_lock));
830842
acl_set_device_op_execution_status(op, -1);
831843
return;
832844
}
833-
// Tell CSR it's valid
834-
acl_get_hal()->write_csr(host_pipe_info.m_physical_device_id, valid_reg,
835-
(void *)&valid, (size_t)sizeof(uintptr_t));
845+
846+
// In non-blocking case, there is no need to write into valid register.
847+
if (blocking) {
848+
// Tell CSR it's valid
849+
acl_get_hal()->write_csr(host_pipe_info.m_physical_device_id, valid_reg,
850+
(void *)&valid, (size_t)sizeof(uintptr_t));
851+
852+
// Wait until the valid reg is 0
853+
unsigned valid_value = 1;
854+
unsigned *valid_value_pointer = &valid_value;
855+
856+
while (valid_value != 0) {
857+
acl_get_hal()->read_csr(host_pipe_info.m_physical_device_id, valid_reg,
858+
(void *)valid_value_pointer,
859+
(size_t)sizeof(uintptr_t));
860+
}
861+
}
836862
} else {
837863
// Regular hostpipe
838864
// Attempt to write once

0 commit comments

Comments
 (0)