Une MAJ de sécurité est nécessaire sur notre version actuelle. Elle sera effectuée lundi 02/08 entre 12h30 et 13h. L'interruption de service devrait durer quelques minutes (probablement moins de 5 minutes).

Commit 45772e4c authored by THIBAULT Samuel's avatar THIBAULT Samuel
Browse files

clean up example code

parent a0942b55
Pipeline #217377 canceled with stage
CC = gcc
STARPU_VERSION=1.3
CFLAGS += -O3 $(shell pkg-config --cflags starpu-$(STARPU_VERSION))
CPPFLAGS += $(shell pkg-config --cflags starpu-$(STARPU_VERSION))
LDLIBS += $(shell pkg-config --libs starpu-$(STARPU_VERSION))
CFLAGS += -Wall -Wextra
# to avoid having to use LD_LIBRARY_PATH
LDLIBS += -Wl,-rpath -Wl,$(shell pkg-config --variable=libdir starpu-$(STARPU_VERSION))
......@@ -27,7 +29,7 @@ all: mult_bench
endif
%.o: %.cu
nvcc $(CFLAGS) $< -c -o $@
nvcc $(CPPFLAGS) $< -c -o $@
vector_scal_task_insert: vector_scal_task_insert.o vector_scal_cpu.o
vector_scal_task_insert_filter: vector_scal_task_insert_filter.o vector_scal_cpu.o
......
/* StarPU --- Runtime system for heterogeneous multicore architectures.
*
* Copyright (C) 2009-2013, 2019 Université de Bordeaux 1
* Copyright (C) 2009-2013, 2019, 2021 Université de Bordeaux 1
* Copyright (C) 2010 Mehdi Juhoor <mjuhoor@gmail.com>
* Copyright (C) 2010, 2011, 2012, 2013, 2014 Centre National de la Recherche Scientifique
*
......@@ -136,13 +136,13 @@ static void mult_kernel_common(void *descr[], int type)
TYPE *subB = (TYPE *)STARPU_MATRIX_GET_PTR(descr[1]);
TYPE *subC = (TYPE *)STARPU_MATRIX_GET_PTR(descr[2]);
unsigned nxC = STARPU_MATRIX_GET_NX(descr[2]);
unsigned nyC = STARPU_MATRIX_GET_NY(descr[2]);
unsigned nyA = STARPU_MATRIX_GET_NY(descr[0]);
int nxC = STARPU_MATRIX_GET_NX(descr[2]);
int nyC = STARPU_MATRIX_GET_NY(descr[2]);
int nyA = STARPU_MATRIX_GET_NY(descr[0]);
unsigned ldA = STARPU_MATRIX_GET_LD(descr[0]);
unsigned ldB = STARPU_MATRIX_GET_LD(descr[1]);
unsigned ldC = STARPU_MATRIX_GET_LD(descr[2]);
int ldA = STARPU_MATRIX_GET_LD(descr[0]);
int ldB = STARPU_MATRIX_GET_LD(descr[1]);
int ldC = STARPU_MATRIX_GET_LD(descr[2]);
if (type == STARPU_CPU)
{
......@@ -161,7 +161,7 @@ static void mult_kernel_common(void *descr[], int type)
int block_size = (nyC + worker_size - 1)/worker_size;
int new_nyC = STARPU_MIN(nyC, block_size*(rank+1)) - block_size*rank;
STARPU_ASSERT(nyC = STARPU_MATRIX_GET_NY(descr[1]));
STARPU_ASSERT(nyC == STARPU_MATRIX_GET_NY(descr[1]));
TYPE *new_subB = &subB[block_size*rank];
TYPE *new_subC = &subC[block_size*rank];
......
......@@ -29,12 +29,11 @@ void vector_scal_cpu(float *val, unsigned n, float factor)
val[i] *= factor;
}
int main(int argc, char **argv)
int main(void)
{
/* We consider a vector of float that is initialized just as any of C
* data */
float *vector;
double start_time;
unsigned i;
vector = malloc(sizeof(vector[0]) * NX);
......@@ -47,7 +46,6 @@ int main(int argc, char **argv)
vector_scal_cpu(vector, NX, factor);
fprintf(stderr, "AFTER First element is %f\n", vector[0]);
free(vector);
return 0;
}
/* StarPU --- Runtime system for heterogeneous multicore architectures.
*
* Copyright (C) 2010, 2011 Université de Bordeaux 1
* Copyright (C) 2010, 2011, 2021 Université de Bordeaux 1
* Copyright (C) 2010, 2011, 2012, 2013, 2014 Centre National de la Recherche Scientifique
*
* StarPU is free software; you can redistribute it and/or modify
......@@ -20,12 +20,6 @@
/* This kernel takes a buffer and scales it by a constant factor */
void vector_scal_cpu(void *buffers[], void *cl_arg)
{
unsigned i;
float factor;
/* extract the value arguments */
starpu_codelet_unpack_args(cl_arg, &factor);
/*
* The "buffers" array matches the task->handles array: for instance
* task->handles[0] is a handle that corresponds to a data with
......@@ -38,14 +32,20 @@ void vector_scal_cpu(void *buffers[], void *cl_arg)
*/
struct starpu_vector_interface *vector = buffers[0];
/* length of the vector */
unsigned n = STARPU_VECTOR_GET_NX(vector);
/* get a pointer to the local copy of the vector : note that we have to
* cast it in (float *) since a vector could contain any type of
* elements so that the .ptr field is actually a uintptr_t */
float *val = (float *)STARPU_VECTOR_GET_PTR(vector);
/* length of the vector */
unsigned n = STARPU_VECTOR_GET_NX(vector);
/* extract the value arguments */
float factor;
starpu_codelet_unpack_args(cl_arg, &factor);
unsigned i;
/* scale the vector */
for (i = 0; i < n; i++)
val[i] *= factor;
......
/* StarPU --- Runtime system for heterogeneous multicore architectures.
*
* Copyright (C) 2010, 2011 Université de Bordeaux 1
* Copyright (C) 2010, 2011, 2021 Université de Bordeaux 1
* Copyright (C) 2010, 2011, 2012, 2013, 2014 Centre National de la Recherche Scientifique
*
* StarPU is free software; you can redistribute it and/or modify
......@@ -26,15 +26,15 @@ static __global__ void vector_mult_cuda(float *val, unsigned int n, float factor
extern "C" void vector_scal_cuda(void *buffers[], void *_args)
{
float factor;
/* extract the value arguments */
starpu_codelet_unpack_args(_args, &factor);
/* length of the vector */
unsigned int n = STARPU_VECTOR_GET_NX(buffers[0]);
/* local copy of the vector pointer */
float *val = (float *)STARPU_VECTOR_GET_PTR(buffers[0]);
/* extract the value arguments */
float factor;
starpu_codelet_unpack_args(_args, &factor);
unsigned threads_per_block = 64;
unsigned nblocks = (n + threads_per_block-1) / threads_per_block;
......
/* StarPU --- Runtime system for heterogeneous multicore architectures.
*
* Copyright (C) 2010, 2011, 2019 Université de Bordeaux 1
* Copyright (C) 2010, 2011, 2019, 2021 Université de Bordeaux 1
* Copyright (C) 2010, 2011, 2012, 2013, 2014 Centre National de la Recherche Scientifique
*
* StarPU is free software; you can redistribute it and/or modify
......@@ -21,20 +21,21 @@ extern struct starpu_opencl_program programs;
void vector_scal_opencl(void *buffers[], void *_args)
{
float factor;
int id, devid, err;
cl_kernel kernel;
cl_command_queue queue;
cl_event event;
/* length of the vector */
unsigned n = STARPU_VECTOR_GET_NX(buffers[0]);
/* OpenCL copy of the vector pointer */
cl_mem val = (cl_mem) STARPU_VECTOR_GET_DEV_HANDLE(buffers[0]);
/* extract the value arguments */
float factor;
starpu_codelet_unpack_args(_args, &factor);
/* Load the OpenCL kernel */
int id, devid, err;
cl_kernel kernel;
cl_command_queue queue;
cl_event event;
id = starpu_worker_get_id();
devid = starpu_worker_get_devid(id);
......
/* StarPU --- Runtime system for heterogeneous multicore architectures.
*
* Copyright (C) 2010, 2011, 2012, 2013, 2014 Centre National de la Recherche Scientifique
* Copyright (C) 2010-2012, 2014, 2019 Université de Bordeaux 1
* Copyright (C) 2010-2012, 2014, 2019, 2021 Université de Bordeaux 1
*
* 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
......@@ -37,24 +37,26 @@ static struct starpu_perfmodel perfmodel = {
static struct starpu_codelet cl = {
/* CPU implementation of the codelet */
.cpu_funcs = {vector_scal_cpu, NULL},
.cpu_funcs = {vector_scal_cpu},
#ifdef STARPU_SIMGRID
/* CUDA pseudo-implementation of the codelet */
.cuda_funcs = {(void*) 1, NULL},
.cuda_funcs = {(void*) 1},
/* OpenCL pseudo-implementation of the codelet */
.opencl_funcs = {(void*) 1, NULL},
.opencl_funcs = {(void*) 1},
#else
#ifdef STARPU_USE_CUDA
/* CUDA implementation of the codelet */
.cuda_funcs = {vector_scal_cuda, NULL},
.cuda_funcs = {vector_scal_cuda},
#endif
#ifdef STARPU_USE_OPENCL
/* OpenCL implementation of the codelet */
.opencl_funcs = {vector_scal_opencl, NULL},
.opencl_funcs = {vector_scal_opencl},
#endif
#endif
.nbuffers = 1,
.modes = {STARPU_RW},
.model = &perfmodel,
};
......@@ -62,7 +64,7 @@ static struct starpu_codelet cl = {
struct starpu_opencl_program programs;
#endif
int main(int argc, char **argv)
int main(void)
{
/* We consider a vector of float that is initialized just as any of C
* data */
......@@ -70,12 +72,6 @@ int main(int argc, char **argv)
double start_time;
unsigned i;
vector = malloc(sizeof(vector[0]) * NX);
for (i = 0; i < NX; i++)
vector[i] = 1.0f;
fprintf(stderr, "BEFORE : First element was %f\n", vector[0]);
/* Initialize StarPU with default configuration */
int ret = starpu_init(NULL);
STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
......@@ -84,6 +80,12 @@ int main(int argc, char **argv)
starpu_opencl_load_opencl_from_file("vector_scal_opencl_kernel.cl", &programs, NULL);
#endif
vector = malloc(sizeof(vector[0]) * NX);
for (i = 0; i < NX; i++)
vector[i] = 1.0f;
fprintf(stderr, "BEFORE : First element was %f\n", vector[0]);
/* Tell StaPU to associate the "vector" vector with the "vector_handle"
* identifier. When a task needs to access a piece of data, it should
* refer to the handle that is associated to it.
......
/* StarPU --- Runtime system for heterogeneous multicore architectures.
*
* Copyright (C) 2010, 2011, 2012, 2013, 2014 Centre National de la Recherche Scientifique
* Copyright (C) 2010-2012, 2014, 2019 Université de Bordeaux 1
* Copyright (C) 2010-2012, 2014, 2019, 2021 Université de Bordeaux 1
*
* 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
......@@ -63,7 +63,7 @@ static struct starpu_codelet cl = {
struct starpu_opencl_program programs;
#endif
int main(int argc, char **argv)
int main(void)
{
/* We consider a vector of float that is initialized just as any of C
* data */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment