static int submit(struct starpu_codelet *codelet, struct starpu_perfmodel *model)
{
	int nloops = 123;
	int loop;
	starpu_data_handle_t handle;
	struct starpu_perfmodel lmodel;
	int ret;
	int old_nsamples, new_nsamples;
	struct starpu_conf conf;
	unsigned archid, archtype, devid, ncore;

	starpu_conf_init(&conf);
	conf.sched_policy_name = "eager";
	conf.calibrate = 1;

	ret = starpu_init(&conf);
	if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");

	codelet->model = model;

        starpu_vector_data_register(&handle, -1, (uintptr_t)NULL, 100, sizeof(int));
	for (loop = 0; loop < nloops; loop++)
	{
		ret = starpu_task_insert(codelet, STARPU_W, handle, 0);
		if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
		STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
	}
        starpu_data_unregister(handle);
	starpu_shutdown();
	return EXIT_SUCCESS;
}
Esempio n. 2
0
static int
run(struct starpu_sched_policy *policy)
{
    int ret;
    struct starpu_conf conf;
    int i;

    starpu_conf_init(&conf);
    conf.sched_policy = policy;
    ret = starpu_init(&conf);
    if (ret != 0)
        exit(STARPU_TEST_SKIPPED);
    starpu_profiling_status_set(1);

    struct starpu_codelet clA =
    {
        .cpu_funcs = {A},
        .nbuffers = 0
    };

    struct starpu_codelet clB =
    {
        .cpu_funcs = {B},
        .nbuffers = 0
    };

    starpu_srand48(0);

    for (i = 0; i < NTASKS; i++)
    {
        struct starpu_task *task = starpu_task_create();

        if (((int)(starpu_drand48()*2))%2)
        {
            task->cl = &clA;
            task->priority=STARPU_MIN_PRIO;
        }
        else
        {
            task->cl = &clB;
            task->priority=STARPU_MAX_PRIO;
        }
        task->detach=1;
        ret = starpu_task_submit(task);
        if (ret == -ENODEV) goto enodev;
        STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
    }

    starpu_task_wait_for_all();
    FPRINTF(stdout,"\n");

    starpu_shutdown();
    return 0;

enodev:
    starpu_shutdown();
    return -ENODEV;
}
int main(int argc, char **argv)
{
	int ret;

	struct starpu_conf conf;
	starpu_conf_init(&conf);

	conf.sched_policy_name = "eager";
	conf.calibrate = 2;

	ret = starpu_initialize(&conf, &argc, &argv);
	if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");

#ifdef STARPU_USE_OPENCL
	ret = starpu_opencl_load_opencl_from_file("tests/perfmodels/opencl_memset_kernel.cl",
						  &opencl_program, NULL);
	STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_load_opencl_from_file");
#endif

	int slog;
	for (slog = START_LOG; slog < END_LOG; slog++)
	{
		int size = 1 << slog;
		test_memset(size);
	}

#ifdef STARPU_USE_OPENCL
        ret = starpu_opencl_unload_opencl(&opencl_program);
        STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_unload_opencl");
#endif

	starpu_shutdown();

	return EXIT_SUCCESS;
}
Esempio n. 4
0
int dotest(struct starpu_disk_ops *ops, void *param)
{
	double *A,*B,*C,*D,*E,*F;
	int ret;

	/* limit main ram to force to push in disk */
	setenv("STARPU_LIMIT_CPU_MEM", RAM, 1);

	/* Initialize StarPU without GPU devices to make sure the memory of the GPU devices will not be used */
	struct starpu_conf conf;
	ret = starpu_conf_init(&conf);
	if (ret == -EINVAL)
		return EXIT_FAILURE;
	conf.ncuda = 0;
	conf.nopencl = 0;
	ret = starpu_init(&conf);
	if (ret == -ENODEV) goto enodev;

	/* register a disk */
	int new_dd = starpu_disk_register(ops, param, 1024*1024*DISK);
	/* can't write on /tmp/ */
	if (new_dd == -ENOENT) goto enoent;

	/* allocate two memory spaces */
	starpu_malloc_flags((void **)&A, NX*sizeof(double), STARPU_MALLOC_COUNT);
	starpu_malloc_flags((void **)&F, NX*sizeof(double), STARPU_MALLOC_COUNT);

	FPRINTF(stderr, "TEST DISK MEMORY \n");

	unsigned int j;
	/* initialization with bad values */
	for(j = 0; j < NX; ++j)
	{
		A[j] = j;
		F[j] = -j;
	}

	starpu_data_handle_t vector_handleA, vector_handleB, vector_handleC, vector_handleD, vector_handleE, vector_handleF;

	/* register vector in starpu */
	starpu_vector_data_register(&vector_handleA, STARPU_MAIN_RAM, (uintptr_t)A, NX, sizeof(double));
	starpu_vector_data_register(&vector_handleB, -1, (uintptr_t) NULL, NX, sizeof(double));
	starpu_vector_data_register(&vector_handleC, -1, (uintptr_t) NULL, NX, sizeof(double));
	starpu_vector_data_register(&vector_handleD, -1, (uintptr_t) NULL, NX, sizeof(double));
	starpu_vector_data_register(&vector_handleE, -1, (uintptr_t) NULL, NX, sizeof(double));
	starpu_vector_data_register(&vector_handleF, STARPU_MAIN_RAM, (uintptr_t)F, NX, sizeof(double));

	/* copy vector A->B, B->C... */
	starpu_data_cpy(vector_handleB, vector_handleA, 0, NULL, NULL);
	starpu_data_cpy(vector_handleC, vector_handleB, 0, NULL, NULL);
	starpu_data_cpy(vector_handleD, vector_handleC, 0, NULL, NULL);
	starpu_data_cpy(vector_handleE, vector_handleD, 0, NULL, NULL);
	starpu_data_cpy(vector_handleF, vector_handleE, 0, NULL, NULL);

	/* StarPU does not need to manipulate the array anymore so we can stop
 	 * monitoring it */

	/* free them */
	starpu_data_unregister(vector_handleA);
	starpu_data_unregister(vector_handleB);
	starpu_data_unregister(vector_handleC);
	starpu_data_unregister(vector_handleD);
	starpu_data_unregister(vector_handleE);
	starpu_data_unregister(vector_handleF);

	/* check if computation is correct */
	int try = 1;
	for (j = 0; j < NX; ++j)
		if (A[j] != F[j])
		{
			FPRINTF(stderr, "Fail A %f != F %f \n", A[j], F[j]);
			try = 0;
		}
static int
test_cpu(void)
{
	int ret, var = 0;
	static starpu_pthread_t driver_thread;
	struct starpu_conf conf;
	struct starpu_driver d =
	{
		.type = STARPU_CPU_WORKER,
		.id.cpu_id = 0
	};

	starpu_conf_init(&conf);
	conf.n_not_launched_drivers = 1;
	conf.not_launched_drivers = &d;
	conf.ncpus = 1;
	ret = starpu_init(&conf);
	if (ret == -ENODEV || starpu_cpu_worker_get_count() == 0)
	{
		FPRINTF(stderr, "WARNING: No CPU worker found\n");
		if (ret == 0)
			starpu_shutdown();
		return STARPU_TEST_SKIPPED;
	}

	ret = starpu_pthread_create(&driver_thread, NULL, run_driver, &d);
	if (ret != 0)
	{
		ret = 1;
		goto out2;
	}

	struct starpu_task *task;
	task = starpu_task_create();
	cl.where = STARPU_CPU;
	task->cl = &cl;
	task->cl_arg = &var;
	task->synchronous = 1;

	ret = starpu_task_submit(task);
	if (ret == -ENODEV)
	{
		FPRINTF(stderr, "WARNING: No worker can execute this task\n");
		ret = STARPU_TEST_SKIPPED;
		goto out;
	}

	FPRINTF(stderr, "[CPU] Var = %d (expected value: 1)\n", var);
	ret = !!(var != 1);
out:
	starpu_drivers_request_termination();
	if (starpu_pthread_join(driver_thread, NULL) != 0)
		return 1;
out2:
	starpu_shutdown();
	return ret;
}
#endif /* STARPU_USE_CPU */

#ifdef STARPU_USE_CUDA
static int
test_cuda(void)
{
	int ret, var = 0;
	static starpu_pthread_t driver_thread;
	struct starpu_conf conf;
	struct starpu_driver d =
	{
		.type = STARPU_CUDA_WORKER,
		.id.cuda_id = 0
	};

	starpu_conf_init(&conf);
	conf.n_not_launched_drivers = 1;
	conf.not_launched_drivers = &d;
	conf.ncuda = 1;
	ret = starpu_init(&conf);
	if (ret == -ENODEV || starpu_cuda_worker_get_count() == 0)
	{
		FPRINTF(stderr, "WARNING: No CUDA worker found\n");
		if (ret == 0)
			starpu_shutdown();
		return STARPU_TEST_SKIPPED;
	}

	ret = starpu_pthread_create(&driver_thread, NULL, run_driver, &d);
	if (ret == -1)
	{
		ret = 1;
		goto out;
	}

	struct starpu_task *task;
	task = starpu_task_create();
	cl.where = STARPU_CUDA;
	task->cl = &cl;
	task->cl_arg = &var;
	task->synchronous = 1;

	ret = starpu_task_submit(task);
	if (ret == -ENODEV)
	{
		FPRINTF(stderr, "WARNING: No worker can execute this task\n");
		ret = STARPU_TEST_SKIPPED;
		goto out;
	}

out:
	starpu_drivers_request_termination();
	if (starpu_pthread_join(driver_thread, NULL) != 0)
		return 1;
	starpu_shutdown();

	FPRINTF(stderr, "[CUDA] Var = %d (expected value: 1)\n", var);
	ret = !!(var != 1);
	return ret;
}
#endif /* STARPU_USE_CUDA */

#ifdef STARPU_USE_OPENCL
static int
test_opencl(void)
{
	int ret, var = 0;
	static starpu_pthread_t driver_thread;
	struct starpu_conf conf;

	cl_int err;
        cl_uint pdummy;
        cl_platform_id platform;
        err = clGetPlatformIDs(1, &platform, &pdummy);
        if (err != CL_SUCCESS)
	{
		FPRINTF(stderr, "WARNING: No OpenCL platform found\n");
		return STARPU_TEST_SKIPPED;
	}

	cl_device_type device_type = CL_DEVICE_TYPE_GPU|CL_DEVICE_TYPE_ACCELERATOR;
	if (starpu_get_env_number("STARPU_OPENCL_ON_CPUS") > 0)
		device_type |= CL_DEVICE_TYPE_CPU;
	if (starpu_get_env_number("STARPU_OPENCL_ONLY_ON_CPUS") > 0)
		device_type = CL_DEVICE_TYPE_CPU;

	cl_device_id device_id;
        err = clGetDeviceIDs(platform, device_type, 1, &device_id, NULL);
        if (err != CL_SUCCESS)
	{
		FPRINTF(stderr, "WARNING: No GPU devices found on OpenCL platform\n");
		return STARPU_TEST_SKIPPED;
	}

	struct starpu_driver d =
	{
		.type = STARPU_OPENCL_WORKER,
		.id.opencl_id = device_id
	};

	starpu_conf_init(&conf);
	conf.n_not_launched_drivers = 1;
	conf.not_launched_drivers = &d;
	conf.ncuda = 0;
	conf.nopencl = 1;
	ret = starpu_init(&conf);
	if (ret == -ENODEV || starpu_opencl_worker_get_count() == 0)
	{
		FPRINTF(stderr, "WARNING: No OpenCL workers found\n");
		if (ret == 0)
			starpu_shutdown();
		return STARPU_TEST_SKIPPED;
	}

	ret = starpu_pthread_create(&driver_thread, NULL, run_driver, &d);
	if (ret == -1)
	{
		ret = 1;
		goto out;
	}

	struct starpu_task *task;
	task = starpu_task_create();
	cl.where = STARPU_OPENCL;
	task->cl = &cl;
	task->cl_arg = &var;
	task->synchronous = 1;

	ret = starpu_task_submit(task);
	if (ret == -ENODEV)
	{
		FPRINTF(stderr, "WARNING: No worker can execute the task\n");
		ret = STARPU_TEST_SKIPPED;
		goto out;
	}

out:
	starpu_drivers_request_termination();
	if (starpu_pthread_join(driver_thread, NULL) != 0)
		return 1;
	starpu_shutdown();

	FPRINTF(stderr, "[OpenCL] Var = %d (expected value: 1)\n", var);
	ret = !!(var != 1);
	return ret;
}
#endif /* STARPU_USE_OPENCL */

int
main(void)
{
	int ret = STARPU_TEST_SKIPPED;
#ifdef STARPU_USE_CPU
	ret = test_cpu();
	if (ret == 1)
		return 1;
#endif
#ifdef STARPU_USE_CUDA
	ret = test_cuda();
	if (ret == 1)
		return 1;
#endif
#ifdef STARPU_USE_OPENCL
	ret = test_opencl();
	if (ret == 1)
		return 1;
#endif
	return ret;
}
Esempio n. 6
0
void starpu_my_vector_data_register(starpu_data_handle_t *handleptr, unsigned home_node,
                        uintptr_t ptr, uint32_t nx, size_t elemsize)
{
	struct starpu_vector_interface vector =
	{
		.id = STARPU_VECTOR_INTERFACE_ID,
		.ptr = ptr,
		.nx = nx,
		.elemsize = elemsize,
                .dev_handle = ptr,
		.slice_base = 0,
                .offset = 0
	};

	starpu_data_register(handleptr, home_node, &vector, &starpu_interface_my_vector_ops);
}

int dotest(struct starpu_disk_ops *ops, char *base)
{
	int *A, *C;

	/* Initialize StarPU without GPU devices to make sure the memory of the GPU devices will not be used */
	struct starpu_conf conf;
	int ret = starpu_conf_init(&conf);
	if (ret == -EINVAL)
		return EXIT_FAILURE;
	conf.ncuda = 0;
	conf.nopencl = 0;
	ret = starpu_init(&conf);
	if (ret == -ENODEV) goto enodev;

	/* Initialize path and name */
	const char *name_file_start = "STARPU_DISK_COMPUTE_DATA_";
	const char *name_file_end = "STARPU_DISK_COMPUTE_DATA_RESULT_";

	char * path_file_start = malloc(strlen(base) + 1 + strlen(name_file_start) + 1);
	strcpy(path_file_start, base);
	strcat(path_file_start, "/");
	strcat(path_file_start, name_file_start);

	char * path_file_end = malloc(strlen(base) + 1 + strlen(name_file_end) + 1);
	strcpy(path_file_end, base);
	strcat(path_file_end, "/");
	strcat(path_file_end, name_file_end);

	/* register a disk */
	int new_dd = starpu_disk_register(ops, (void *) base, 1024*1024*1);
	/* can't write on /tmp/ */
	if (new_dd == -ENOENT) goto enoent;

	unsigned dd = (unsigned) new_dd;

	/* allocate two memory spaces */
	starpu_malloc_flags((void **)&A, NX*sizeof(int), STARPU_MALLOC_COUNT);
	starpu_malloc_flags((void **)&C, NX*sizeof(int), STARPU_MALLOC_COUNT);

	FPRINTF(stderr, "TEST DISK MEMORY \n");

	unsigned int j;
	/* you register them in a vector */
	for(j = 0; j < NX; ++j)
	{
		A[j] = j;
		C[j] = 0;
	}

	/* you create a file to store the vector ON the disk */
	FILE * f = fopen(path_file_start, "wb+");
	if (f == NULL)
		goto enoent2;

	/* store it in the file */
	fwrite(A, sizeof(int), NX, f);

	/* close the file */
	fclose(f);

	int descriptor = open(path_file_start, O_RDWR);
#ifdef STARPU_HAVE_WINDOWS
	_commit(descriptor);
#else
	fsync(descriptor);
#endif
	close(descriptor);

	/* create a file to store result */
	f = fopen(path_file_end, "wb+");
	if (f == NULL)
		goto enoent2;

	/* replace all datas by 0 */
	fwrite(C, sizeof(int), NX, f);

	/* close the file */
	fclose(f);

        descriptor = open(path_file_end, O_RDWR);
#ifdef STARPU_HAVE_WINDOWS
        _commit(descriptor);
#else
        fsync(descriptor);
#endif
	close(descriptor);

	/* And now, you want to use your datas in StarPU */
	/* Open the file ON the disk */
	void * data = starpu_disk_open(dd, (void *) name_file_start, NX*sizeof(int));
	void * data_result = starpu_disk_open(dd, (void *) name_file_end, NX*sizeof(int));

	starpu_data_handle_t vector_handleA, vector_handleC;

	/* Build an vector-like interface which doesn't have the any_to_any helper, to force making use of pack/unpack */
	memcpy(&starpu_interface_my_vector_ops, &starpu_interface_vector_ops, sizeof(starpu_interface_my_vector_ops));
	starpu_interface_my_vector_ops.copy_methods = &my_vector_copy_data_methods_s;

	/* register vector in starpu */
	starpu_my_vector_data_register(&vector_handleA, dd, (uintptr_t) data, NX, sizeof(int));

	/* and do what you want with it, here we copy it into an other vector */
	starpu_my_vector_data_register(&vector_handleC, dd, (uintptr_t) data_result, NX, sizeof(int));

	starpu_data_cpy(vector_handleC, vector_handleA, 0, NULL, NULL);

	/* free them */
	starpu_data_unregister(vector_handleA);
	starpu_data_unregister(vector_handleC);

	/* close them in StarPU */
	starpu_disk_close(dd, data, NX*sizeof(int));
	starpu_disk_close(dd, data_result, NX*sizeof(int));

	/* check results */
	f = fopen(path_file_end, "rb+");
	if (f == NULL)
		goto enoent2;
	/* take datas */
	fread(C, sizeof(int), NX, f);

	/* close the file */
	fclose(f);

	int try = 1;
	for (j = 0; j < NX; ++j)
		if (A[j] != C[j])
		{
			FPRINTF(stderr, "Fail A %d != C %d \n", A[j], C[j]);
			try = 0;
		}