Browse Source

- add example of a native Fortran variable nbuffer codelet

Olivier Aumage 8 years ago
parent
commit
5059767c36

+ 14 - 1
examples/Makefile.am

@@ -250,7 +250,8 @@ STARPU_EXAMPLES +=				\
 	native_fortran/nf_vector		\
 	native_fortran/nf_matrix		\
 	native_fortran/nf_example		\
-	native_fortran/nf_dynbuf
+	native_fortran/nf_dynbuf		\
+	native_fortran/nf_varbuf
 endif
 endif
 endif
@@ -403,6 +404,11 @@ native_fortran_nf_dynbuf_SOURCES =	\
 	native_fortran/nf_dynbuf_cl.f90		\
 	$(top_srcdir)/include/fstarpu_mod.f90	\
 	native_fortran/nf_dynbuf.f90
+
+native_fortran_nf_varbuf_SOURCES =	\
+	native_fortran/nf_varbuf_cl.f90		\
+	$(top_srcdir)/include/fstarpu_mod.f90	\
+	native_fortran/nf_varbuf.f90
 endif
 
 #######################
@@ -1037,6 +1043,7 @@ nf_compute.mod: nf_compute.o
 fstarpu_mod.mod: fstarpu_mod.o
 nf_codelets.mod: nf_codelets.o
 nf_dynbuf_cl.mod: nf_dynbuf_cl.o
+nf_varbuf_cl.mod: nf_varbuf_cl.o
 
 fstarpu_mod.o: $(top_srcdir)/include/fstarpu_mod.f90
 	$(AM_V_FC)$(FC) $(native_fortran_nf_vector_FCFLAGS) $(FCFLAGS) -c -o $@ '$(top_srcdir)/'include/fstarpu_mod.f90
@@ -1062,4 +1069,10 @@ nf_dynbuf_cl.o: $(top_srcdir)/examples/native_fortran/nf_dynbuf_cl.f90 nf_types.
 nf_dynbuf.o: $(top_srcdir)/examples/native_fortran/nf_dynbuf.f90 nf_types.mod nf_dynbuf_cl.mod fstarpu_mod.mod
 	$(AM_V_FC)$(FC) $(native_fortran_nf_dynbuf_FCFLAGS) $(FCFLAGS) -c -o $@ `test -f 'native_fortran/nf_dynbuf.f90' || echo '$(srcdir)/'`native_fortran/nf_dynbuf.f90
 
+nf_varbuf_cl.o: $(top_srcdir)/examples/native_fortran/nf_varbuf_cl.f90 nf_types.mod fstarpu_mod.mod
+	$(AM_V_FC)$(FC) $(native_fortran_nf_varbuf_FCFLAGS) $(FCFLAGS) -c -o $@ `test -f 'native_fortran/nf_varbuf_cl.f90' || echo '$(srcdir)/'`native_fortran/nf_varbuf_cl.f90
+
+nf_varbuf.o: $(top_srcdir)/examples/native_fortran/nf_varbuf.f90 nf_types.mod nf_varbuf_cl.mod fstarpu_mod.mod
+	$(AM_V_FC)$(FC) $(native_fortran_nf_varbuf_FCFLAGS) $(FCFLAGS) -c -o $@ `test -f 'native_fortran/nf_varbuf.f90' || echo '$(srcdir)/'`native_fortran/nf_varbuf.f90
+
 endif

+ 47 - 0
examples/native_fortran/Makefile.nf_varbuf

@@ -0,0 +1,47 @@
+# StarPU --- Runtime system for heterogeneous multicore architectures.
+#
+# Copyright (C) 2015-2016  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.
+
+PROG = nf_varbuf
+
+FSTARPU_MOD = $(shell pkg-config --cflags-only-I starpu-1.3|sed -e 's/^\([^ ]*starpu\/1.3\).*$$/\1/;s/^.* //;s/^-I//')/fstarpu_mod.f90
+
+SRCSF = nf_varbuf_cl.f90	\
+	nf_varbuf.f90
+
+FC = gfortran
+
+FCFLAGS = -fdefault-real-8 -J. -g
+LDLIBS =  $(shell pkg-config --libs starpu-1.3)
+
+OBJS = fstarpu_mod.o $(SRCSF:%.f90=%.o)
+
+.phony: all clean
+all: $(PROG)
+
+$(PROG): $(OBJS)
+	$(FC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
+
+fstarpu_mod.o: $(FSTARPU_MOD)
+	$(FC) $(FCFLAGS) -c -o $@ $<
+
+%.o: %.f90
+	$(FC) $(FCFLAGS) -c -o $@ $<
+
+clean:
+	rm -fv *.o *.mod $(PROG)
+
+# modfiles generation dependences
+nf_varbuf_cl.o: nf_varbuf_cl.f90 fstarpu_mod.o
+nf_varbuf.o: nf_varbuf.f90 nf_types.o fstarpu_mod.o

+ 83 - 0
examples/native_fortran/nf_varbuf.f90

@@ -0,0 +1,83 @@
+! StarPU --- Runtime system for heterogeneous multicore architectures.
+!
+! Copyright (C) 2016  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.
+
+program nf_varbuf
+        use iso_c_binding       ! C interfacing module
+        use fstarpu_mod         ! StarPU interfacing module
+        use nf_varbuf_cl
+        implicit none
+
+        type(c_ptr) :: cl_varbuf   ! a pointer for the codelet structure
+        type(c_ptr) :: dh_var
+        type(c_ptr) :: descrs_var
+        integer(c_int),target :: nbuffers
+        integer(c_int) :: err   ! return status for fstarpu_init
+        integer(c_int) :: ncpu  ! number of cpus workers
+
+        integer(c_int),target :: var
+        integer(c_int) :: i
+
+        integer(c_int), parameter :: nb_buf_begin = 1
+        integer(c_int), parameter :: nb_buf_end   = 8
+
+        var = 42
+
+        ! initialize StarPU with default settings
+        err = fstarpu_init(C_NULL_PTR)
+        if (err == -19) then
+                stop 77
+        end if
+
+        ! stop there if no CPU worker available
+        ncpu = fstarpu_cpu_worker_get_count()
+        if (ncpu == 0) then
+                call fstarpu_shutdown()
+                stop 77
+        end if
+
+        ! allocate an empty codelet structure
+        cl_varbuf = fstarpu_codelet_allocate()
+        call fstarpu_codelet_set_name(cl_varbuf, C_CHAR_"dummy_kernel"//C_NULL_CHAR)
+        call fstarpu_codelet_add_cpu_func(cl_varbuf, C_FUNLOC(cl_cpu_func_varbuf))
+        ! mark codelet as accepting a variable set of buffers
+        call fstarpu_codelet_set_variable_nbuffers(cl_varbuf)
+
+        call fstarpu_variable_data_register(dh_var, 0, c_loc(var), c_sizeof(var))
+
+        do nbuffers = nb_buf_begin, nb_buf_end
+                write(*,*) "nbuffers=", nbuffers
+
+                descrs_var = fstarpu_data_descr_array_alloc(nbuffers)
+                do i=0,nbuffers-1
+                        call fstarpu_data_descr_array_set(descrs_var, i, dh_var, FSTARPU_RW)
+                end do
+                call fstarpu_insert_task((/ cl_varbuf, &
+                        FSTARPU_VALUE, c_loc(nbuffers), FSTARPU_SZ_C_INT, &
+                        FSTARPU_DATA_MODE_ARRAY, descrs_var, c_loc(nbuffers), &
+                        C_NULL_PTR /))
+                call fstarpu_data_descr_array_free(descrs_var)
+        end do
+
+        call fstarpu_task_wait_for_all()
+
+        call fstarpu_data_unregister(dh_var)
+
+        ! free codelet structure
+        call fstarpu_codelet_free(cl_varbuf)
+
+        ! shut StarPU down
+        call fstarpu_shutdown()
+
+end program nf_varbuf

+ 38 - 0
examples/native_fortran/nf_varbuf_cl.f90

@@ -0,0 +1,38 @@
+! StarPU --- Runtime system for heterogeneous multicore architectures.
+!
+! Copyright (C) 2016  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.
+
+module nf_varbuf_cl
+contains
+recursive subroutine cl_cpu_func_varbuf (buffers, cl_args) bind(C)
+        use iso_c_binding       ! C interfacing module
+        use fstarpu_mod         ! StarPU interfacing module
+        implicit none
+
+        type(c_ptr), value, intent(in) :: buffers, cl_args ! cl_args is unused
+        integer(c_int),target :: nb_data
+        integer(c_int),pointer :: val
+        integer(c_int) :: i
+
+        call fstarpu_unpack_arg(cl_args,(/ c_loc(nb_data) /))
+        write(*,*) "number of data:", nb_data
+        do i=0,nb_data-1
+                call c_f_pointer(fstarpu_variable_get_ptr(buffers, i), val)
+                write(*,*) "i:", i, ", val:", val
+                if (val /= 42) then
+                        stop 1
+                end if
+        end do
+end subroutine cl_cpu_func_varbuf
+end module nf_varbuf_cl