Skip to content

Commit e8a57e6

Browse files
author
zibai.wang
committed
fixed some bugs
1 parent 62d711a commit e8a57e6

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

include/acl_types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ typedef struct _cl_kernel {
922922
// Eventually this should be an array of ACLDeviceBinaries similar
923923
// to how cl_program contains an array of dev_prog.
924924
const acl_device_binary_t *dev_bin;
925-
int processed_buffer_size;
925+
size_t processed_buffer_size;
926926
} _cl_kernel;
927927

928928
ACL_DECLARE_CL_OBJECT_ALLOC_FUNCTIONS(cl_kernel);
@@ -1347,7 +1347,7 @@ typedef struct {
13471347
// it sees the CL_COMPLETE status for the first time, but it won't
13481348
// change after that.
13491349
cl_uint num_printf_bytes_pending;
1350-
int debug_dump; // TODO, initialize to 0, somewhere
1350+
int debug_dump = 0; // TODO, initialize to 0, somewhere
13511351
} acl_device_op_info_t;
13521352

13531353
// An operation to be performed on a device.

src/acl_printf.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#pragma GCC visibility push(protected)
3939
#endif
4040

41-
static void l_dump_printf_buffer(cl_event event, cl_kernel kernel,
41+
static size_t l_dump_printf_buffer(cl_event event, cl_kernel kernel,
4242
unsigned size);
4343
static void decode_string(std::string &print_data);
4444

@@ -719,12 +719,13 @@ static std::string::const_iterator get_data_elem_at_offset(
719719
return end_of_string;
720720
}
721721

722-
static void l_dump_printf_buffer(cl_event event, cl_kernel kernel,
722+
static size_t l_dump_printf_buffer(cl_event event, cl_kernel kernel,
723723
unsigned size) {
724724
unsigned global_offset; // the location in the printf buffer
725725
unsigned single_printf_offset; // the offset of a single printf
726726
void (*hal_dma_fn)(cl_event, const void *, void *, size_t) = 0;
727727
int src_on_host = 1;
728+
size_t dumped_buffer_size = 0;
728729
#ifdef _WIN32
729730
__declspec(align(64)) char
730731
buffer[ACL_PRINTF_BUFFER_TOTAL_SIZE]; // Aligned to 64, for dma transfers
@@ -743,11 +744,11 @@ static void l_dump_printf_buffer(cl_event event, cl_kernel kernel,
743744
if (!verify_types()) {
744745
printf("Host data types are incompatible with ACL compiler, ignoring "
745746
"printfs...\n");
746-
return;
747+
return dumped_buffer_size;
747748
}
748749

749750
if (printf_infos.empty())
750-
return;
751+
return dumped_buffer_size;
751752

752753
// Memory is on the device if all of these are true:
753754
// The memory is not SVM or the device does not support SVM.
@@ -783,9 +784,10 @@ static void l_dump_printf_buffer(cl_event event, cl_kernel kernel,
783784
if (size > (unsigned int) kernel->processed_buffer_size){
784785
printf("ZIBAI has something to print! \n");
785786
hal_dma_fn(NULL, unprocessed_begin, buffer, size - kernel->processed_buffer_size);
787+
dumped_buffer_size = size - kernel->processed_buffer_size;
786788
} else{
787789
printf("Zibai Added, nothing to print \n");
788-
return;
790+
return dumped_buffer_size;
789791
}
790792

791793

@@ -839,7 +841,7 @@ static void l_dump_printf_buffer(cl_event event, cl_kernel kernel,
839841
if (!success) {
840842
acl_print_debug_msg(
841843
"corrupt printf data, ignoring remaining printfs...\n");
842-
return;
844+
return dumped_buffer_size;
843845
}
844846

845847
#ifdef DEBUG
@@ -902,7 +904,7 @@ static void l_dump_printf_buffer(cl_event event, cl_kernel kernel,
902904
if (vector_size == -1) {
903905
acl_print_debug_msg("wrong vector specifier in printf call, ignoring "
904906
"remaining printfs...\n");
905-
return;
907+
return dumped_buffer_size;
906908
}
907909

908910
// get the length specifier
@@ -923,7 +925,7 @@ static void l_dump_printf_buffer(cl_event event, cl_kernel kernel,
923925
if (size_of_data == 0) {
924926
acl_print_debug_msg("wrong length modifier in printf call, ignoring "
925927
"remaining printfs...\n");
926-
return;
928+
return dumped_buffer_size;
927929
}
928930

929931
for (i = 0; i < vector_size; i++) {
@@ -979,6 +981,7 @@ static void l_dump_printf_buffer(cl_event event, cl_kernel kernel,
979981
#ifdef DEBUG
980982
printf("exiting acl_dump_buffer...\n");
981983
#endif
984+
return dumped_buffer_size;
982985
}
983986

984987
//
@@ -1030,14 +1033,14 @@ void acl_process_printf_buffer(void *user_data, acl_device_op_t *op) {
10301033

10311034
// Grab the printf data and emit it.
10321035
cl_uint num_bytes = op->info.num_printf_bytes_pending;
1033-
l_dump_printf_buffer(event, kernel, num_bytes);
1036+
size_t dumped_buffer_size = l_dump_printf_buffer(event, kernel, num_bytes);
10341037

10351038
// Mark this printf work as done. Must do this *before* unstalling
10361039
// the kernel, to avoid a race against the kernel filling up the
10371040
// buffer again.
10381041
// Zibai Testing
10391042
if (op->info.debug_dump == 1){
1040-
kernel->processed_buffer_size += num_bytes; // TODO, Fix this, should be += processed bytes
1043+
kernel->processed_buffer_size += dumped_buffer_size;
10411044
} else{
10421045
// Full dump, clear this global var
10431046
kernel->processed_buffer_size = 0;
@@ -1049,9 +1052,11 @@ void acl_process_printf_buffer(void *user_data, acl_device_op_t *op) {
10491052
acl_memory_barrier();
10501053

10511054
// Allow the kernel to continue running.
1052-
// Zibai Testing!
1053-
// acl_get_hal()->unstall_kernel(
1054-
// event->cmd.info.ndrange_kernel.device->def.physical_device_id, op->id);
1055+
// We don't need to unstall the kernel during the early flushing during debug.
1056+
if (op->info.debug_dump == 0){
1057+
acl_get_hal()->unstall_kernel(
1058+
event->cmd.info.ndrange_kernel.device->def.physical_device_id, op->id);
1059+
}
10551060
}
10561061
}
10571062

0 commit comments

Comments
 (0)