Skip to content

Commit

Permalink
Relax hostpipe assertion to allow non-byte aligned data type to pass
Browse files Browse the repository at this point in the history
  • Loading branch information
zibaiwan committed Aug 10, 2023
1 parent 3d4e79f commit 1e3604d
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/acl_hostch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,24 @@ static cl_int l_push_packet(unsigned int physical_device_id, int channel_handle,
assert(status == 0);
if (pushed_data == write_size) {
return CL_SUCCESS;
}
// If data type is not byte aligned, such as AC_INT56
// Pushed data can be smaller than the request write_size
// Runtime needs to check if the trailling byte are all 0s.
else if ((pushed_data > 0) && (pushed_data < write_size)) {
for (int i = pushed_data; i < write_size; i++) {
unsigned char c = ((char *)host_buffer)[i];
if (c != 0) {
// This shouldn't happen. Needs to send out a warning to user rather
// than a silent function failure.
std::cerr << "Error: Data is not fully written into the Hostpipe. "
"None-0 bits have been cut off \n";
return CL_INVALID_VALUE;
}
}
return CL_SUCCESS;
} else {
// The packet is the smallest unit of data you can send over.
// If it didn't send the packet, it shouldn't have sent over anything
// Pipe is here in this case. Nothing should be pushed in this case.
assert(pushed_data == 0);
return CL_PIPE_FULL;
}
Expand Down Expand Up @@ -778,16 +793,21 @@ void acl_read_program_hostpipe(void *user_data, acl_device_op_t *op) {

if (!blocking) {
// If it is non-blocking read, we return with the success code right away
if (status != 0 || pulled_data != event->cmd.info.host_pipe_info.size) {
// TODO: Change to pulled_data != pipe.width when sideband signals pipe
// are fully implemented Right now we consider the result is good as long
// as pulled_data > 0.
if (status != 0 || pulled_data == 0) {
acl_mutex_unlock(&(host_pipe_info.m_lock));
acl_set_device_op_execution_status(op, -1);
return;
}
} else {
// If it is a blocking read, this call won't return until the kernel
// writes the data into the pipe.
while (status != 0 ||
pulled_data != event->cmd.info.host_pipe_info.size) {
// TODO: Change to pulled_data == pipe.width when sideband signals pipe
// are fully implemented Right now we consider the result is good as long
// as pulled_data > 0.
while (status != 0 || pulled_data == 0) {
pulled_data = acl_get_hal()->hostchannel_pull(
host_pipe_info.m_physical_device_id,
host_pipe_info.m_channel_handle, event->cmd.info.host_pipe_info.ptr,
Expand Down

0 comments on commit 1e3604d

Please sign in to comment.