@@ -736,17 +736,30 @@ void acl_read_program_hostpipe(void *user_data, acl_device_op_t *op) {
736
736
737
737
// start the CSR read
738
738
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.
740
741
do {
741
742
acl_get_hal ()->read_csr (host_pipe_info.m_physical_device_id , valid_reg,
742
743
(void *)valid_value_pointer,
743
744
(size_t )sizeof (uintptr_t ));
744
- } while (valid_value != 1 );
745
+ } while (blocking && valid_value != 1 );
745
746
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 =
747
755
acl_get_hal ()->read_csr (host_pipe_info.m_physical_device_id , data_reg,
748
756
event->cmd .info .host_pipe_info .ptr ,
749
757
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
+ }
750
763
// Tell CSR it's ready
751
764
acl_get_hal ()->write_csr (host_pipe_info.m_physical_device_id , ready_reg,
752
765
(void *)&ready, (size_t )sizeof (uintptr_t ));
@@ -807,7 +820,6 @@ void acl_write_program_hostpipe(void *user_data, acl_device_op_t *op) {
807
820
// Get CSR address
808
821
unsigned long long parsed;
809
822
uintptr_t data_reg, valid_reg;
810
- size_t pushed_data;
811
823
try {
812
824
parsed = std::stoull (host_pipe_info.csr_address , nullptr );
813
825
} catch (const std::exception &) {
@@ -821,18 +833,32 @@ void acl_write_program_hostpipe(void *user_data, acl_device_op_t *op) {
821
833
// this to the autodiscovery string maybe
822
834
unsigned int valid = 1 ;
823
835
// start the write
824
- pushed_data =
836
+ auto status =
825
837
acl_get_hal ()->write_csr (host_pipe_info.m_physical_device_id , data_reg,
826
838
event->cmd .info .host_pipe_info .write_ptr ,
827
839
event->cmd .info .host_pipe_info .size );
828
- if (pushed_data != event-> cmd . info . host_pipe_info . size ) {
840
+ if (status != 0 ) {
829
841
acl_mutex_unlock (&(host_pipe_info.m_lock ));
830
842
acl_set_device_op_execution_status (op, -1 );
831
843
return ;
832
844
}
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
+ }
836
862
} else {
837
863
// Regular hostpipe
838
864
// Attempt to write once
0 commit comments