| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 | 
							- /* StarPU --- Runtime system for heterogeneous multicore architectures.
 
-  *
 
-  * Copyright (C) 2011  INRIA
 
-  *
 
-  * StarPU is free software; you can redistribute it and/or modify
 
-  * it under the terms of the GNU Lesser General Public License as published by
 
-  * the Free Software Foundation; either version 2.1 of the License, or (at
 
-  * your option) any later version.
 
-  *
 
-  * StarPU is distributed in the hope that it will be useful, but
 
-  * WITHOUT ANY WARRANTY; without even the implied warranty of
 
-  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
-  *
 
-  * See the GNU Lesser General Public License in COPYING.LGPL for more details.
 
-  */
 
- #undef NDEBUG
 
- #include <assert.h>
 
- #include <starpu.h>
 
- #include <stdlib.h>
 
- #include <sys/types.h>
 
- #include "../helper.h"
 
- /*
 
-  * Check that starpu_data_lookup returns the proper data handle, given
 
-  * the registered buffer address
 
-  */
 
- void task(void **buffers, void *args)
 
- {
 
- 	float *numbers;
 
- 	size_t size, i;
 
- 	numbers = (float *) STARPU_VECTOR_GET_PTR(buffers[0]);
 
- 	starpu_codelet_unpack_args (args, &size);
 
- 	for(i = 0; i < size; i++)
 
- 	{
 
- 		numbers[i] = i;
 
- 	}
 
- }
 
- static struct starpu_codelet cl =
 
- {
 
- 	.cpu_funcs = {task},
 
- 	.cpu_funcs_name = {"task"},
 
- 	.nbuffers = 1,
 
- 	.modes = {STARPU_W}
 
- };
 
- static int test_lazy_allocation(void)
 
- {
 
- 	static const size_t count = 123;
 
- 	size_t i;
 
- 	void *pointer;
 
- 	starpu_data_handle_t handle;
 
- 	int ret;
 
- 	/* Lazily-allocated vector.  */
 
- 	starpu_vector_data_register(&handle, -1, 0 /* NULL */,
 
- 				    count, sizeof(float));
 
- 	ret = starpu_task_insert(&cl,
 
- 				 STARPU_W, handle,
 
- 				 STARPU_VALUE, &count, sizeof(size_t),
 
- 				 0);
 
- 	if (ret == -ENODEV) return ret;
 
- 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
 
- 	/* yes, we do not perform the computation but we did detect that no one
 
- 	 * could perform the kernel, so this is not an error from StarPU */
 
- 	/* Acquire the handle, forcing a local allocation.  */
 
- 	ret = starpu_data_acquire(handle, STARPU_R);
 
- 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_data_acquire");
 
- 	/* Make sure we have a local pointer to it.  */
 
- 	pointer = starpu_data_get_local_ptr(handle);
 
- 	STARPU_ASSERT(pointer != NULL);
 
- 	for(i = 0; i < count; i++)
 
- 	{
 
- 		float *numbers = (float *)pointer;
 
- 		STARPU_ASSERT(numbers[i] == i);
 
- 	}
 
- 	/* Make sure the pointer/handle mapping is up-to-date.  */
 
- 	STARPU_ASSERT(starpu_data_lookup(pointer) == handle);
 
- 	starpu_data_release(handle);
 
- 	starpu_data_unregister(handle);
 
- 	STARPU_ASSERT(starpu_data_lookup(pointer) == NULL);
 
- 	return 0;
 
- }
 
- #define VECTOR_COUNT    12
 
- #define VARIABLE_COUNT  42
 
- #define VECTOR_SIZE     123
 
- static void test_filters(void)
 
- {
 
- #define CHILDREN_COUNT 10
 
- 	int ret, i;
 
- 	int *ptr, *children_pointers[CHILDREN_COUNT];
 
- 	starpu_data_handle_t handle;
 
- 	ret = starpu_malloc((void**)&ptr, VECTOR_SIZE * sizeof(*ptr));
 
- 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_malloc");
 
- 	starpu_vector_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)ptr,
 
- 				    VECTOR_SIZE, sizeof(*ptr));
 
- 	struct starpu_data_filter f =
 
- 	{
 
- 		.filter_func = starpu_vector_filter_block,
 
- 		.nchildren = CHILDREN_COUNT
 
- 	};
 
- 	starpu_data_partition(handle, &f);
 
- 	STARPU_ASSERT(starpu_data_get_nb_children(handle) == CHILDREN_COUNT);
 
- 	for (i = 0; i < CHILDREN_COUNT; i++)
 
- 	{
 
-                 starpu_data_handle_t child;
 
- 		child = starpu_data_get_sub_data(handle, 1, i);
 
- 		children_pointers[i] = (int *) starpu_data_get_local_ptr(child);
 
- 		STARPU_ASSERT(children_pointers[i] != NULL);
 
- 		/* Make sure we have a pointer -> handle mapping for CHILD.  */
 
- 		STARPU_ASSERT(starpu_data_lookup(children_pointers[i]) == child);
 
- 	}
 
- 	starpu_data_unpartition(handle, STARPU_MAIN_RAM);
 
- 	for (i = 0; i < CHILDREN_COUNT; i++)
 
- 	{
 
- 		if (children_pointers[i] != ptr)
 
- 			/* Make sure the pointer -> handle mapping is gone.  */
 
- 			STARPU_ASSERT(starpu_data_lookup(children_pointers[i]) == NULL);
 
- 	}
 
- 	/* Make sure the parent's mapping is back.  */
 
- 	STARPU_ASSERT(starpu_data_lookup(ptr) == handle);
 
- 	starpu_data_unregister(handle);
 
- 	starpu_free(ptr);
 
- #undef CHILDREN_COUNT
 
- }
 
- int main(int argc, char *argv[])
 
- {
 
- 	int ret;
 
- 	size_t i;
 
- 	void *vectors[VECTOR_COUNT], *variables[VARIABLE_COUNT];
 
- 	starpu_data_handle_t vector_handles[VECTOR_COUNT];
 
- 	starpu_data_handle_t variable_handles[VARIABLE_COUNT];
 
- 	ret = starpu_initialize(NULL, &argc, &argv);
 
- 	if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
 
- 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
 
- 	/* Register data regions.  */
 
- 	for(i = 0; i < VARIABLE_COUNT; i++)
 
- 	{
 
- 		ret = starpu_malloc(&variables[i], sizeof(float));
 
- 		STARPU_CHECK_RETURN_VALUE(ret, "starpu_malloc");
 
- 		starpu_variable_data_register(&variable_handles[i], STARPU_MAIN_RAM,
 
- 					      (uintptr_t)variables[i],
 
- 					      sizeof(float));
 
- 	}
 
- 	for(i = 0; i < VECTOR_COUNT; i++)
 
- 	{
 
- 		ret = starpu_malloc(&vectors[i], VECTOR_SIZE * sizeof(float));
 
- 		STARPU_CHECK_RETURN_VALUE(ret, "starpu_malloc");
 
- 		starpu_vector_data_register(&vector_handles[i], STARPU_MAIN_RAM,
 
- 					    (uintptr_t)vectors[i],
 
- 					    VECTOR_SIZE, sizeof(float));
 
- 	}
 
- 	/* Look them up.  */
 
- 	for(i = 0; i < VARIABLE_COUNT; i++)
 
- 	{
 
- 		starpu_data_handle_t handle;
 
- 		handle = starpu_data_lookup(variables[i]);
 
- 		STARPU_ASSERT(handle == variable_handles[i]);
 
- 	}
 
- 	for(i = 0; i < VECTOR_COUNT; i++)
 
- 	{
 
- 		starpu_data_handle_t handle;
 
- 		handle = starpu_data_lookup(vectors[i]);
 
- 		STARPU_ASSERT(handle == vector_handles[i]);
 
- 	}
 
- 	/* Unregister them.  */
 
- 	for(i = 0; i < VARIABLE_COUNT; i++)
 
- 	{
 
- 		starpu_data_unregister(variable_handles[i]);
 
- 	}
 
- 	for(i = 0; i < VECTOR_COUNT; i++)
 
- 	{
 
- 		starpu_data_unregister(vector_handles[i]);
 
- 	}
 
- 	/* Make sure we can no longer find them.  */
 
- 	for(i = 0; i < VARIABLE_COUNT; i++)
 
- 	{
 
- 		starpu_data_handle_t handle;
 
- 		handle = starpu_data_lookup(variables[i]);
 
- 		STARPU_ASSERT(handle == NULL);
 
- 		starpu_free(variables[i]);
 
- 	}
 
- 	for(i = 0; i < VECTOR_COUNT; i++)
 
- 	{
 
- 		starpu_data_handle_t handle;
 
- 		handle = starpu_data_lookup(vectors[i]);
 
- 		STARPU_ASSERT(handle == NULL);
 
- 		starpu_free(vectors[i]);
 
- 	}
 
- 	ret = test_lazy_allocation();
 
- 	if (ret == -ENODEV) goto enodev;
 
- 	test_filters();
 
- 	starpu_shutdown();
 
- 	return EXIT_SUCCESS;
 
- enodev:
 
- 	fprintf(stderr, "WARNING: No one can execute this task\n");
 
- 	/* yes, we do not perform the computation but we did detect that no one
 
-  	 * could perform the kernel, so this is not an error from StarPU */
 
- 	starpu_shutdown();
 
- 	return STARPU_TEST_SKIPPED;
 
- }
 
 
  |