Przeglądaj źródła

- add some more native Fortran routines

Olivier Aumage 9 lat temu
rodzic
commit
53809a40c1

+ 2 - 2
examples/native_fortran/nf_example.f90

@@ -72,13 +72,13 @@ PROGRAM f90_example
   CALL fstarpu_codelet_add_buffer(cl_loop_element, FSTARPU_R)
   CALL fstarpu_codelet_add_buffer(cl_loop_element, FSTARPU_RW)
   CALL fstarpu_codelet_add_buffer(cl_loop_element, FSTARPU_R)
-  ! TODO: add name "LOOP_ELEMENT"
+  CALL fstarpu_codelet_set_name(cl_loop_element, C_CHAR_"LOOP_ELEMENT"//C_NULL_CHAR)
 
   cl_copy_element = fstarpu_codelet_allocate()
   CALL fstarpu_codelet_add_cpu_func(cl_copy_element, C_FUNLOC(copy_element_cpu_fortran))
   CALL fstarpu_codelet_add_buffer(cl_copy_element, FSTARPU_RW)
   CALL fstarpu_codelet_add_buffer(cl_copy_element, FSTARPU_R)
-  ! TODO: add name "COPY_ELEMENT"
+  CALL fstarpu_codelet_set_name(cl_copy_element, C_CHAR_"COPY_ELEMENT"//C_NULL_CHAR)
 
   !Registration of elements
   DO i = 1,Nelt

+ 3 - 0
examples/native_fortran/nf_matrix.f90

@@ -44,6 +44,9 @@ program nf_matrix
         ! allocate an empty codelet structure
         cl_mat = fstarpu_codelet_allocate()
 
+        ! set the codelet name
+        call fstarpu_codelet_set_name(cl_mat, C_CHAR_"my_mat_codelet"//C_NULL_CHAR)
+
         ! add a CPU implementation function to the codelet
         call fstarpu_codelet_add_cpu_func(cl_mat, C_FUNLOC(cl_cpu_func_mat))
 

+ 3 - 0
examples/native_fortran/nf_vector.f90

@@ -51,6 +51,9 @@ program nf_vector
         ! allocate an empty codelet structure
         cl_vec = fstarpu_codelet_allocate()
 
+        ! set the codelet name
+        call fstarpu_codelet_set_name(cl_vec, C_CHAR_"my_vec_codelet"//C_NULL_CHAR)
+
         ! add a CPU implementation function to the codelet
         call fstarpu_codelet_add_cpu_func(cl_vec, C_FUNLOC(cl_cpu_func_vec))
 

+ 76 - 3
include/fstarpu_mod.f90

@@ -38,10 +38,65 @@ module fstarpu_mod
         interface
                 ! == starpu.h ==
 
-                subroutine fstarpu_conf_init(conf) bind(C,name="starpu_conf_init")
+                ! starpu_conf_init: see fstarpu_conf_allocate
+
+                function fstarpu_conf_allocate () bind(C)
+                        use iso_c_binding, only: c_ptr
+                        type(c_ptr) :: fstarpu_conf_allocate
+                end function fstarpu_conf_allocate
+
+                subroutine fstarpu_conf_free (cl) bind(C)
                         use iso_c_binding, only: c_ptr
+                        type(c_ptr), value, intent(in) :: cl
+                end subroutine fstarpu_conf_free
+
+                subroutine fstarpu_conf_set_sched_policy_name (conf, policy_name) bind(C)
+                        use iso_c_binding, only: c_ptr, c_char
                         type(c_ptr), value, intent(in) :: conf
-                end subroutine fstarpu_conf_init
+                        character(c_char), intent(in) :: policy_name
+                end subroutine fstarpu_conf_set_sched_policy_name
+
+                subroutine fstarpu_conf_set_min_prio (conf, min_prio) bind(C)
+                        use iso_c_binding, only: c_ptr, c_int
+                        type(c_ptr), value, intent(in) :: conf
+                        integer(c_int), value, intent(in) :: min_prio
+                end subroutine fstarpu_conf_set_min_prio
+
+                subroutine fstarpu_conf_set_max_prio (conf, max_prio) bind(C)
+                        use iso_c_binding, only: c_ptr, c_int
+                        type(c_ptr), value, intent(in) :: conf
+                        integer(c_int), value, intent(in) :: max_prio
+                end subroutine fstarpu_conf_set_max_prio
+
+                subroutine fstarpu_conf_set_ncpu (conf, ncpu) bind(C)
+                        use iso_c_binding, only: c_ptr, c_int
+                        type(c_ptr), value, intent(in) :: conf
+                        integer(c_int), value, intent(in) :: ncpu
+                end subroutine fstarpu_conf_set_ncpu
+
+                subroutine fstarpu_conf_set_ncuda (conf, ncuda) bind(C)
+                        use iso_c_binding, only: c_ptr, c_int
+                        type(c_ptr), value, intent(in) :: conf
+                        integer(c_int), value, intent(in) :: ncuda
+                end subroutine fstarpu_conf_set_ncuda
+
+                subroutine fstarpu_conf_set_nopencl (conf, nopencl) bind(C)
+                        use iso_c_binding, only: c_ptr, c_int
+                        type(c_ptr), value, intent(in) :: conf
+                        integer(c_int), value, intent(in) :: nopencl
+                end subroutine fstarpu_conf_set_nopencl
+
+                subroutine fstarpu_conf_set_nmic (conf, nmic) bind(C)
+                        use iso_c_binding, only: c_ptr, c_int
+                        type(c_ptr), value, intent(in) :: conf
+                        integer(c_int), value, intent(in) :: nmic
+                end subroutine fstarpu_conf_set_nmic
+
+                subroutine fstarpu_conf_set_nscc (conf, nscc) bind(C)
+                        use iso_c_binding, only: c_ptr, c_int
+                        type(c_ptr), value, intent(in) :: conf
+                        integer(c_int), value, intent(in) :: nscc
+                end subroutine fstarpu_conf_set_nscc
 
                 ! starpu_init: see fstarpu_init
                 ! starpu_initialize: see fstarpu_init
@@ -130,6 +185,12 @@ module fstarpu_mod
                         type(c_ptr), value, intent(in) :: cl
                 end subroutine fstarpu_codelet_free
 
+                subroutine fstarpu_codelet_set_name (cl, cl_name) bind(C)
+                        use iso_c_binding, only: c_ptr, c_char
+                        type(c_ptr), value, intent(in) :: cl
+                        character(c_char), intent(in) :: cl_name
+                end subroutine fstarpu_codelet_set_name
+
                 subroutine fstarpu_codelet_add_cpu_func (cl, f_ptr) bind(C)
                         use iso_c_binding, only: c_ptr, c_funptr
                         type(c_ptr), value, intent(in) :: cl
@@ -148,8 +209,20 @@ module fstarpu_mod
                         type(c_funptr), value, intent(in) :: f_ptr
                 end subroutine fstarpu_codelet_add_opencl_func
 
+                subroutine fstarpu_codelet_add_mic_func (cl, f_ptr) bind(C)
+                        use iso_c_binding, only: c_ptr, c_funptr
+                        type(c_ptr), value, intent(in) :: cl
+                        type(c_funptr), value, intent(in) :: f_ptr
+                end subroutine fstarpu_codelet_add_mic_func
+
+                subroutine fstarpu_codelet_add_scc_func (cl, f_ptr) bind(C)
+                        use iso_c_binding, only: c_ptr, c_funptr
+                        type(c_ptr), value, intent(in) :: cl
+                        type(c_funptr), value, intent(in) :: f_ptr
+                end subroutine fstarpu_codelet_add_scc_func
+
                 subroutine fstarpu_codelet_add_buffer (cl, mode) bind(C)
-                        use iso_c_binding, only: c_ptr, c_ptr
+                        use iso_c_binding, only: c_ptr
                         type(c_ptr), value, intent(in) :: cl
                         type(c_ptr), value, intent(in) :: mode ! C function expects an intptr_t
                 end subroutine fstarpu_codelet_add_buffer

+ 106 - 1
src/util/fstarpu.c

@@ -46,10 +46,80 @@ intptr_t fstarpu_get_constant(char *s)
 	else { _FSTARPU_ERROR("unknown pointer constant"); }
 }
 
+struct starpu_conf *fstarpu_conf_allocate(void)
+{
+	struct starpu_conf *conf = malloc(sizeof(*conf));
+	starpu_conf_init(conf);
+	return conf;
+}
+
+void fstarpu_conf_free(struct starpu_conf *conf)
+{
+	memset(conf, 0, sizeof(*conf));
+	free(conf);
+}
+
+void fstarpu_conf_set_sched_policy_name(struct starpu_conf *conf, const char *sched_policy_name)
+{
+	conf->sched_policy_name = sched_policy_name;
+}
+
+void fstarpu_conf_set_min_prio(struct starpu_conf *conf, int min_prio)
+{
+	conf->global_sched_ctx_min_priority = min_prio;
+}
+
+void fstarpu_conf_set_max_prio(struct starpu_conf *conf, int max_prio)
+{
+	conf->global_sched_ctx_max_priority = max_prio;
+}
+
+void fstarpu_conf_set_ncpu(struct starpu_conf *conf, int ncpu)
+{
+	STARPU_ASSERT(ncpu >= 0 && ncpu <= STARPU_NMAXWORKERS);
+	conf->ncpus = ncpu;
+}
+
+void fstarpu_conf_set_ncuda(struct starpu_conf *conf, int ncuda)
+{
+	STARPU_ASSERT(ncuda >= 0 && ncuda <= STARPU_NMAXWORKERS);
+	conf->ncuda = ncuda;
+}
+
+void fstarpu_conf_set_nopencl(struct starpu_conf *conf, int nopencl)
+{
+	STARPU_ASSERT(nopencl >= 0 && nopencl <= STARPU_NMAXWORKERS);
+	conf->nopencl = nopencl;
+}
+
+void fstarpu_conf_set_nmic(struct starpu_conf *conf, int nmic)
+{
+	STARPU_ASSERT(nmic >= 0 && nmic <= STARPU_NMAXWORKERS);
+	conf->nmic = nmic;
+}
+
+void fstarpu_conf_set_nscc(struct starpu_conf *conf, int nscc)
+{
+	STARPU_ASSERT(nscc >= 0 && nscc <= STARPU_NMAXWORKERS);
+	conf->nscc = nscc;
+}
+
+void fstarpu_conf_set_calibrate(struct starpu_conf *conf, int calibrate)
+{
+	STARPU_ASSERT(calibrate == 0 || calibrate == 1);
+	conf->calibrate = calibrate;
+}
+
+void fstarpu_conf_set_bus_calibrate(struct starpu_conf *conf, int bus_calibrate)
+{
+	STARPU_ASSERT(bus_calibrate == 0 || bus_calibrate == 1);
+	conf->bus_calibrate = bus_calibrate;
+}
+
 struct starpu_codelet *fstarpu_codelet_allocate(void)
 {
 	struct starpu_codelet *cl = malloc(sizeof(*cl));
-	memset(cl, 0, sizeof(*cl));
+	starpu_codelet_init(cl);
 	return cl;
 }
 
@@ -59,6 +129,11 @@ void fstarpu_codelet_free(struct starpu_codelet *cl)
 	free(cl);
 }
 
+void fstarpu_codelet_set_name(struct starpu_codelet *cl, const char *cl_name)
+{
+	cl->name = cl_name;
+}
+
 void fstarpu_codelet_add_cpu_func(struct starpu_codelet *cl, void *f_ptr)
 {
 	const size_t max_cpu_funcs = sizeof(cl->cpu_funcs)/sizeof(cl->cpu_funcs[0])-1;
@@ -104,6 +179,36 @@ void fstarpu_codelet_add_opencl_func(struct starpu_codelet *cl, void *f_ptr)
 	_FSTARPU_ERROR("fstarpu: too many opencl functions in Fortran codelet");
 }
 
+void fstarpu_codelet_add_mic_func(struct starpu_codelet *cl, void *f_ptr)
+{
+	const size_t max_mic_funcs = sizeof(cl->mic_funcs)/sizeof(cl->mic_funcs[0])-1;
+	int i;
+	for (i = 0; i < max_mic_funcs; i++)
+	{
+		if (cl->mic_funcs[i] == NULL)
+		{
+			cl->mic_funcs[i] = f_ptr;
+			return;
+		}
+	}
+	_FSTARPU_ERROR("fstarpu: too many mic functions in Fortran codelet");
+}
+
+void fstarpu_codelet_add_scc_func(struct starpu_codelet *cl, void *f_ptr)
+{
+	const size_t max_scc_funcs = sizeof(cl->scc_funcs)/sizeof(cl->scc_funcs[0])-1;
+	int i;
+	for (i = 0; i < max_scc_funcs; i++)
+	{
+		if (cl->scc_funcs[i] == NULL)
+		{
+			cl->scc_funcs[i] = f_ptr;
+			return;
+		}
+	}
+	_FSTARPU_ERROR("fstarpu: too many scc functions in Fortran codelet");
+}
+
 void fstarpu_codelet_add_buffer(struct starpu_codelet *cl, intptr_t mode)
 {
 	const size_t max_modes = sizeof(cl->modes)/sizeof(cl->modes[0])-1;