Browse Source

- add native Fortran support for setting various codelet flags (main flags, cuda/opencl flags, where flags)

Olivier Aumage 8 years ago
parent
commit
7e735b6fef
3 changed files with 122 additions and 0 deletions
  1. 3 0
      examples/native_fortran/nf_vector.f90
  2. 55 0
      include/fstarpu_mod.f90
  3. 64 0
      src/util/fstarpu.c

+ 3 - 0
examples/native_fortran/nf_vector.f90

@@ -57,6 +57,9 @@ program nf_vector
         ! add a CPU implementation function to the codelet
         call fstarpu_codelet_add_cpu_func(cl_vec, C_FUNLOC(cl_cpu_func_vec))
 
+        ! optionally set 'where' field to CPU only
+        call fstarpu_codelet_set_where(cl_vec, FSTARPU_CPU)
+
         ! add a Read-only mode data buffer to the codelet
         call fstarpu_codelet_add_buffer(cl_vec, FSTARPU_R)
 

+ 55 - 0
include/fstarpu_mod.f90

@@ -74,6 +74,17 @@ module fstarpu_mod
         type(c_ptr), bind(C) :: FSTARPU_SCHED_CTX_POLICY_INIT
         type(c_ptr), bind(C) :: FSTARPU_SCHED_CTX_USER_DATA
 
+        type(c_ptr), bind(C) :: FSTARPU_NOWHERE
+        type(c_ptr), bind(C) :: FSTARPU_CPU
+        type(c_ptr), bind(C) :: FSTARPU_CUDA
+        type(c_ptr), bind(C) :: FSTARPU_OPENCL
+        type(c_ptr), bind(C) :: FSTARPU_MIC
+        type(c_ptr), bind(C) :: FSTARPU_SCC
+
+        type(c_ptr), bind(C) :: FSTARPU_CODELET_SIMGRID_EXECUTE
+        type(c_ptr), bind(C) :: FSTARPU_CUDA_ASYNC
+        type(c_ptr), bind(C) :: FSTARPU_OPENCL_ASYNC
+
         ! (some) portable iso_c_binding types
         type(c_ptr), bind(C) :: FSTARPU_SZ_C_DOUBLE
         type(c_ptr), bind(C) :: FSTARPU_SZ_C_FLOAT
@@ -655,12 +666,24 @@ module fstarpu_mod
                         type(c_funptr), value, intent(in) :: f_ptr
                 end subroutine fstarpu_codelet_add_cuda_func
 
+                subroutine fstarpu_codelet_add_cuda_flags (cl, flags) bind(C)
+                        use iso_c_binding, only: c_ptr
+                        type(c_ptr), value, intent(in) :: cl
+                        type(c_ptr), value, intent(in) :: flags ! C function expects an intptr_t
+                end subroutine fstarpu_codelet_add_cuda_flags
+
                 subroutine fstarpu_codelet_add_opencl_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_opencl_func
 
+                subroutine fstarpu_codelet_add_opencl_flags (cl, flags) bind(C)
+                        use iso_c_binding, only: c_ptr
+                        type(c_ptr), value, intent(in) :: cl
+                        type(c_ptr), value, intent(in) :: flags ! C function expects an intptr_t
+                end subroutine fstarpu_codelet_add_opencl_flags
+
                 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
@@ -690,6 +713,18 @@ module fstarpu_mod
                         integer(c_int), value, intent(in) :: nbuffers
                 end subroutine fstarpu_codelet_set_nbuffers
 
+                subroutine fstarpu_codelet_set_flags (cl, flags) bind(C)
+                        use iso_c_binding, only: c_ptr
+                        type(c_ptr), value, intent(in) :: cl
+                        type(c_ptr), value, intent(in) :: flags ! C function expects an intptr_t
+                end subroutine fstarpu_codelet_set_flags
+
+                subroutine fstarpu_codelet_set_where (cl, where) bind(C)
+                        use iso_c_binding, only: c_ptr
+                        type(c_ptr), value, intent(in) :: cl
+                        type(c_ptr), value, intent(in) :: where ! C function expects an intptr_t
+                end subroutine fstarpu_codelet_set_where
+
                 ! == starpu_data_interface.h ==
 
                 ! uintptr_t starpu_malloc_on_node_flags(unsigned dst_node, size_t size, int flags);
@@ -2282,6 +2317,26 @@ module fstarpu_mod
                         FSTARPU_SCHED_CTX_USER_DATA    = &
                             fstarpu_get_constant(C_CHAR_"FSTARPU_SCHED_CTX_USER_DATA"//C_NULL_CHAR)
 
+                        FSTARPU_NOWHERE = &
+                            fstarpu_get_constant(C_CHAR_"FSTARPU_NOWHERE"//C_NULL_CHAR)
+                        FSTARPU_CPU = &
+                            fstarpu_get_constant(C_CHAR_"FSTARPU_CPU"//C_NULL_CHAR)
+                        FSTARPU_CUDA = &
+                            fstarpu_get_constant(C_CHAR_"FSTARPU_CUDA"//C_NULL_CHAR)
+                        FSTARPU_OPENCL = &
+                            fstarpu_get_constant(C_CHAR_"FSTARPU_OPENCL"//C_NULL_CHAR)
+                        FSTARPU_MIC = &
+                            fstarpu_get_constant(C_CHAR_"FSTARPU_MIC"//C_NULL_CHAR)
+                        FSTARPU_SCC = &
+                            fstarpu_get_constant(C_CHAR_"FSTARPU_SCC"//C_NULL_CHAR)
+
+                        FSTARPU_CODELET_SIMGRID_EXECUTE = &
+                            fstarpu_get_constant(C_CHAR_"FSTARPU_CODELET_SIMGRID_EXECUTE"//C_NULL_CHAR)
+                        FSTARPU_CUDA_ASYNC = &
+                            fstarpu_get_constant(C_CHAR_"FSTARPU_CUDA_ASYNC"//C_NULL_CHAR)
+                        FSTARPU_OPENCL_ASYNC = &
+                            fstarpu_get_constant(C_CHAR_"FSTARPU_OPENCL_ASYNC"//C_NULL_CHAR)
+
                         ! Initialize size constants as 'c_ptr'
                         FSTARPU_SZ_C_DOUBLE        = sz_to_p(c_sizeof(FSTARPU_SZ_C_DOUBLE_dummy))
                         FSTARPU_SZ_C_FLOAT        = sz_to_p(c_sizeof(FSTARPU_SZ_C_FLOAT_dummy))

+ 64 - 0
src/util/fstarpu.c

@@ -77,6 +77,18 @@ static const intptr_t fstarpu_sched_ctx_awake_workers	= STARPU_SCHED_CTX_AWAKE_W
 static const intptr_t fstarpu_sched_ctx_policy_init	= STARPU_SCHED_CTX_POLICY_INIT;
 static const intptr_t fstarpu_sched_ctx_user_data	= STARPU_SCHED_CTX_USER_DATA;
 
+static const intptr_t fstarpu_starpu_nowhere	= STARPU_NOWHERE;
+static const intptr_t fstarpu_starpu_cpu	= STARPU_CPU;
+static const intptr_t fstarpu_starpu_cuda	= STARPU_CUDA;
+static const intptr_t fstarpu_starpu_opencl	= STARPU_OPENCL;
+static const intptr_t fstarpu_starpu_mic	= STARPU_MIC;
+static const intptr_t fstarpu_starpu_scc	= STARPU_SCC;
+
+static const intptr_t fstarpu_starpu_codelet_simgrid_execute	= STARPU_CODELET_SIMGRID_EXECUTE;
+static const intptr_t fstarpu_starpu_cuda_async	= STARPU_CUDA_ASYNC;
+static const intptr_t fstarpu_starpu_opencl_async	= STARPU_OPENCL_ASYNC;
+
+
 intptr_t fstarpu_get_constant(char *s)
 {
 	if	(!strcmp(s, "FSTARPU_R"))	{ return fstarpu_r; }
@@ -133,6 +145,17 @@ intptr_t fstarpu_get_constant(char *s)
 	else if (!strcmp(s, "FSTARPU_SCHED_CTX_POLICY_INIT"))	{ return fstarpu_sched_ctx_policy_init; }
 	else if (!strcmp(s, "FSTARPU_SCHED_CTX_USER_DATA"))	{ return fstarpu_sched_ctx_user_data; }
 
+	else if (!strcmp(s, "FSTARPU_NOWHERE"))	{ return fstarpu_starpu_nowhere; }
+	else if (!strcmp(s, "FSTARPU_CPU"))	{ return fstarpu_starpu_cpu; }
+	else if (!strcmp(s, "FSTARPU_CUDA"))	{ return fstarpu_starpu_cuda; }
+	else if (!strcmp(s, "FSTARPU_OPENCL"))	{ return fstarpu_starpu_opencl; }
+	else if (!strcmp(s, "FSTARPU_MIC"))	{ return fstarpu_starpu_mic; }
+	else if (!strcmp(s, "FSTARPU_SCC"))	{ return fstarpu_starpu_scc; }
+
+	else if (!strcmp(s, "FSTARPU_CODELET_SIMGRID_EXECUTE"))	{ return fstarpu_starpu_codelet_simgrid_execute; }
+	else if (!strcmp(s, "FSTARPU_CUDA_ASYNC"))	{ return fstarpu_starpu_cuda_async; }
+	else if (!strcmp(s, "FSTARPU_OPENCL_ASYNC"))	{ return fstarpu_starpu_opencl_async; }
+
 	else { _FSTARPU_ERROR("unknown constant"); }
 }
 
@@ -259,6 +282,21 @@ void fstarpu_codelet_add_cuda_func(struct starpu_codelet *cl, void *f_ptr)
 	_FSTARPU_ERROR("fstarpu: too many cuda functions in Fortran codelet");
 }
 
+void fstarpu_codelet_add_cuda_flags(struct starpu_codelet *cl, intptr_t flags)
+{
+	const size_t max_cuda_flags = sizeof(cl->cuda_flags)/sizeof(cl->cuda_flags[0])-1;
+	unsigned i;
+	for (i = 0; i < max_cuda_flags; i++)
+	{
+		if (cl->cuda_flags[i] == NULL)
+		{
+			cl->cuda_flags[i] = (char)flags;
+			return;
+		}
+	}
+	_FSTARPU_ERROR("fstarpu: too many cuda flags in Fortran codelet");
+}
+
 void fstarpu_codelet_add_opencl_func(struct starpu_codelet *cl, void *f_ptr)
 {
 	const size_t max_opencl_funcs = sizeof(cl->opencl_funcs)/sizeof(cl->opencl_funcs[0])-1;
@@ -274,6 +312,21 @@ 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_opencl_flags(struct starpu_codelet *cl, intptr_t flags)
+{
+	const size_t max_opencl_flags = sizeof(cl->opencl_flags)/sizeof(cl->opencl_flags[0])-1;
+	unsigned i;
+	for (i = 0; i < max_opencl_flags; i++)
+	{
+		if (cl->opencl_flags[i] == NULL)
+		{
+			cl->opencl_flags[i] = (char)flags;
+			return;
+		}
+	}
+	_FSTARPU_ERROR("fstarpu: too many opencl flags 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;
@@ -341,6 +394,17 @@ void fstarpu_codelet_set_nbuffers(struct starpu_codelet *cl, int nbuffers)
 	}
 }
 
+void fstarpu_codelet_set_flags(struct starpu_codelet *cl, intptr_t flags)
+{
+	cl->flags = (int)flags;
+}
+
+void fstarpu_codelet_set_where(struct starpu_codelet *cl, intptr_t where)
+{
+	STARPU_ASSERT(where >= 0);
+	cl->where = (uint32_t)where;
+}
+
 void * fstarpu_variable_get_ptr(void *buffers[], int i)
 {
 	return (void *)STARPU_VECTOR_GET_PTR(buffers[i]);