Browse Source

Data interface: add new function int starpu_data_interface_get_next_id() which returns the next id available for a data interface. That ensures different data interface registered by application all have different ids.

Nathalie Furmento 13 years ago
parent
commit
203765dbd8

+ 5 - 3
examples/filters/custom_mf/custom_interface.c

@@ -96,8 +96,7 @@ static void     display_custom_interface(starpu_data_handle_t handle, FILE *f);
 static uint32_t custom_get_nx(starpu_data_handle_t handle);
 
 
-static struct starpu_multiformat_data_interface_ops*
-get_mf_ops(void *data_interface)
+static struct starpu_multiformat_data_interface_ops*get_mf_ops(void *data_interface)
 {
 	struct custom_data_interface *custom;
 	custom = (struct custom_data_interface *) data_interface;
@@ -118,7 +117,7 @@ static struct starpu_data_interface_ops interface_custom_ops =
 #ifdef STARPU_USE_GORDON
 	.convert_to_gordon     = NULL,
 #endif
-	.interfaceid           = STARPU_NINTERFACES_ID+1, //XXX
+	.interfaceid           = -1,
 	.interface_size        = sizeof(struct custom_data_interface),
 	.display               = display_custom_interface,
 	.is_multiformat        = 1,
@@ -372,6 +371,9 @@ void custom_data_register(starpu_data_handle_t *handle,
 		.ops = format_ops
 	};
 
+	if (interface_custom_ops.interfaceid == -1) {
+		interface_custom_ops.interfaceid = starpu_data_interface_get_next_id();
+	}
 	starpu_data_register(handle, home_node, &custom, &interface_custom_ops);
 }
 

+ 4 - 1
include/starpu_data_interfaces.h

@@ -97,7 +97,7 @@ enum starpu_data_interface_id
 	STARPU_VARIABLE_INTERFACE_ID=5,
 	STARPU_VOID_INTERFACE_ID=6,
 	STARPU_MULTIFORMAT_INTERFACE_ID=7,
-	STARPU_NINTERFACES_ID=8 /* number of data interfaces */
+	STARPU_MAX_INTERFACE_ID=8 /* maximum number of data interfaces */
 };
 
 struct starpu_data_interface_ops
@@ -137,6 +137,9 @@ struct starpu_data_interface_ops
 	struct starpu_multiformat_data_interface_ops* (*get_mf_ops)(void *data_interface);
 };
 
+/* Return the next available id for a data interface */
+int starpu_data_interface_get_next_id();
+
 void starpu_data_register(starpu_data_handle_t *handleptr, uint32_t home_node, void *data_interface, struct starpu_data_interface_ops *ops);
 
 /* Return the pointer associated with HANDLE on node NODE or NULL if HANDLE's

+ 7 - 0
src/datawizard/interfaces/data_interface.c

@@ -34,6 +34,7 @@ struct handle_entry
 /* Hash table mapping host pointers to data handles.  */
 static struct handle_entry *registered_handles;
 static struct _starpu_spinlock    registered_handles_lock;
+static int _data_interface_number = STARPU_MAX_INTERFACE_ID;
 
 void _starpu_data_interface_init()
 {
@@ -583,3 +584,9 @@ void *starpu_data_get_interface_on_node(starpu_data_handle_t handle, unsigned me
 {
 	return handle->per_node[memory_node].data_interface;
 }
+
+int starpu_data_interface_get_next_id()
+{
+	_data_interface_number += 1;
+	return _data_interface_number-1;
+}