Преглед изворни кода

port r15815 from starpu-on-mpi branch: Fix arithmetic on void *

Samuel Thibault пре 9 година
родитељ
комит
fef8ca9445

+ 2 - 2
src/drivers/mp_common/mp_common.c

@@ -239,7 +239,7 @@ void _starpu_mp_common_send_command(const struct _starpu_mp_node *node,
 
 
 	/* Let's copy the data into the command line buffer */
 	/* Let's copy the data into the command line buffer */
 	memcpy(node->buffer, &command, command_size);
 	memcpy(node->buffer, &command, command_size);
-	memcpy(node->buffer + command_size, &arg_size, arg_size_size);
+	memcpy((void*) ((uintptr_t)node->buffer + command_size), &arg_size, arg_size_size);
 
 
 	node->mp_send(node, node->buffer, command_size + arg_size_size);
 	node->mp_send(node, node->buffer, command_size + arg_size_size);
 
 
@@ -265,7 +265,7 @@ enum _starpu_mp_command _starpu_mp_common_recv_command(const struct _starpu_mp_n
 	node->mp_recv(node, node->buffer, command_size + arg_size_size);
 	node->mp_recv(node, node->buffer, command_size + arg_size_size);
 
 
 	command = *((enum _starpu_mp_command *) node->buffer);
 	command = *((enum _starpu_mp_command *) node->buffer);
-	*arg_size = *((int *) (node->buffer + command_size));
+	*arg_size = *((int *) ((uintptr_t)node->buffer + command_size));
 
 
 	/* If there is no argument (ie. arg_size == 0),
 	/* If there is no argument (ie. arg_size == 0),
 	 * let's return the command right now */
 	 * let's return the command right now */

+ 5 - 5
src/drivers/mp_common/sink_common.c

@@ -156,7 +156,7 @@ static void _starpu_sink_common_recv_workers(struct _starpu_mp_node * node, void
 {
 {
 	/* Retrieve information from the message */
 	/* Retrieve information from the message */
 	STARPU_ASSERT(arg_size == (sizeof(int)*5));
 	STARPU_ASSERT(arg_size == (sizeof(int)*5));
-	void * arg_ptr = arg;
+	uintptr_t arg_ptr = (uintptr_t) arg;
 	int i;
 	int i;
 
 
 	int nworkers = *(int *)arg_ptr;
 	int nworkers = *(int *)arg_ptr;
@@ -559,7 +559,7 @@ void _starpu_sink_common_execute(struct _starpu_mp_node *node,
 {
 {
 	unsigned i;
 	unsigned i;
 
 
-	void *arg_ptr = arg;
+	uintptr_t arg_ptr = (uintptr_t) arg;
 	struct mp_task *task = malloc(sizeof(struct mp_task));
 	struct mp_task *task = malloc(sizeof(struct mp_task));
 
 
 	task->kernel = *(void(**)(void **, void *)) arg_ptr;
 	task->kernel = *(void(**)(void **, void *)) arg_ptr;
@@ -592,15 +592,15 @@ void _starpu_sink_common_execute(struct _starpu_mp_node *node,
 	for (i = 0; i < task->nb_interfaces; i++)
 	for (i = 0; i < task->nb_interfaces; i++)
 	{
 	{
 		union _starpu_interface * interface = malloc(sizeof(union _starpu_interface));
 		union _starpu_interface * interface = malloc(sizeof(union _starpu_interface));
-		memcpy(interface, arg_ptr,
+		memcpy(interface, (void*) arg_ptr,
 				sizeof(union _starpu_interface));
 				sizeof(union _starpu_interface));
 		task->interfaces[i] = interface;
 		task->interfaces[i] = interface;
 		arg_ptr += sizeof(union _starpu_interface);
 		arg_ptr += sizeof(union _starpu_interface);
 	}
 	}
 
 
 	/* Was cl_arg sent ? */
 	/* Was cl_arg sent ? */
-	if (arg_size > arg_ptr - arg)
-		task->cl_arg = arg_ptr;
+	if (arg_size > arg_ptr - (uintptr_t) arg)
+		task->cl_arg = (void*) arg_ptr;
 	else
 	else
 		task->cl_arg = NULL;
 		task->cl_arg = NULL;
 
 

+ 6 - 4
src/drivers/mp_common/source_common.c

@@ -313,7 +313,8 @@ int _starpu_src_common_execute_kernel(struct _starpu_mp_node *node,
 		void *cl_arg, size_t cl_arg_size)
 		void *cl_arg, size_t cl_arg_size)
 {
 {
 
 
-	void *buffer, *buffer_ptr, *arg =NULL;
+	void *buffer, *arg =NULL;
+	uintptr_t buffer_ptr;
 	int buffer_size = 0, arg_size =0;
 	int buffer_size = 0, arg_size =0;
 	unsigned i;
 	unsigned i;
 
 
@@ -337,7 +338,8 @@ int _starpu_src_common_execute_kernel(struct _starpu_mp_node *node,
 	 * a pointer to the function (sink-side), core on which execute this
 	 * a pointer to the function (sink-side), core on which execute this
 	 * function (sink-side), number of interfaces we send,
 	 * function (sink-side), number of interfaces we send,
 	 * an array of generic (union) interfaces and the value of cl_arg */
 	 * an array of generic (union) interfaces and the value of cl_arg */
-	buffer_ptr = buffer = (void *) malloc(buffer_size);
+	buffer = (void *) malloc(buffer_size);
+	buffer_ptr = (uintptr_t) buffer;
 
 
 	*(void(**)(void)) buffer = kernel;
 	*(void(**)(void)) buffer = kernel;
 	buffer_ptr += sizeof(kernel);
 	buffer_ptr += sizeof(kernel);
@@ -369,7 +371,7 @@ int _starpu_src_common_execute_kernel(struct _starpu_mp_node *node,
 	{
 	{
 		starpu_data_handle_t handle = handles[i];
 		starpu_data_handle_t handle = handles[i];
 
 
-		memcpy (buffer_ptr, interfaces[i],
+		memcpy ((void*) buffer_ptr, interfaces[i],
 				handle->ops->interface_size);
 				handle->ops->interface_size);
 		/* The sink side has no mean to get the type of each
 		/* The sink side has no mean to get the type of each
 		 * interface, we use a union to make it generic and permit the
 		 * interface, we use a union to make it generic and permit the
@@ -378,7 +380,7 @@ int _starpu_src_common_execute_kernel(struct _starpu_mp_node *node,
 	}
 	}
 
 
 	if (cl_arg)
 	if (cl_arg)
-		memcpy(buffer_ptr, cl_arg, cl_arg_size);
+		memcpy((void*) buffer_ptr, cl_arg, cl_arg_size);
 
 
 	_starpu_mp_common_send_command(node, STARPU_EXECUTE, buffer, buffer_size);
 	_starpu_mp_common_send_command(node, STARPU_EXECUTE, buffer, buffer_size);
 	enum _starpu_mp_command answer = _starpu_src_common_wait_command_sync(node, &arg, &arg_size);
 	enum _starpu_mp_command answer = _starpu_src_common_wait_command_sync(node, &arg, &arg_size);