diff options
author | Antoniu Pop <antoniu.pop@gmail.com> | 2008-02-20 21:09:23 +0000 |
---|---|---|
committer | Sebastian Pop <sebastian.pop@amd.com> | 2008-02-20 21:09:23 +0000 |
commit | e3ec9c236066f7e8795455ea5ae1de382c24f8e2 (patch) | |
tree | 596dfc9336e66d6cfd63dadca223a0781b0e7899 | |
parent | 9ab08f201c82c9d0be930c42487971fbe56a51dd (diff) |
2008-02-05 Antoniu Pop <antoniu.pop@gmail.com>
Sebastian Pop <sebastian.pop@amd.com>
* Makefile.in: Regenerated.
* stream.c: New.
* libgomp.h (gomp_stream): New.
(gomp_stream_create, gomp_stream_used_space, gomp_stream_free_space,
gomp_stream_wait_used_space, gomp_stream_wait_free_space,
gomp_stream_push, gomp_stream_pop, gomp_stream_eos_p,
gomp_stream_set_eos, gomp_stream_destroy): Declared.
* Makefile.am (libgomp_la_SOURCES): Add dependence on stream.c.
git-svn-id: https://gcc.gnu.org/svn/gcc/branches/graphite@132495 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | libgomp/ChangeLog.graphite | 11 | ||||
-rw-r--r-- | libgomp/Makefile.am | 3 | ||||
-rw-r--r-- | libgomp/Makefile.in | 6 | ||||
-rw-r--r-- | libgomp/libgomp.h | 36 | ||||
-rw-r--r-- | libgomp/stream.c | 130 |
5 files changed, 183 insertions, 3 deletions
diff --git a/libgomp/ChangeLog.graphite b/libgomp/ChangeLog.graphite new file mode 100644 index 00000000000..6eb1d8f1dcd --- /dev/null +++ b/libgomp/ChangeLog.graphite @@ -0,0 +1,11 @@ +2008-02-05 Antoniu Pop <antoniu.pop@gmail.com> + Sebastian Pop <sebastian.pop@amd.com> + + * Makefile.in: Regenerated. + * stream.c: New. + * libgomp.h (gomp_stream): New. + (gomp_stream_create, gomp_stream_used_space, gomp_stream_free_space, + gomp_stream_wait_used_space, gomp_stream_wait_free_space, + gomp_stream_push, gomp_stream_pop, gomp_stream_eos_p, + gomp_stream_set_eos, gomp_stream_destroy): Declared. + * Makefile.am (libgomp_la_SOURCES): Add dependence on stream.c. diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am index 55e3bf3ee15..2c3e508154c 100644 --- a/libgomp/Makefile.am +++ b/libgomp/Makefile.am @@ -31,7 +31,8 @@ libgomp_la_LDFLAGS = $(libgomp_version_info) $(libgomp_version_script) libgomp_la_SOURCES = alloc.c barrier.c critical.c env.c error.c iter.c \ loop.c ordered.c parallel.c sections.c single.c team.c work.c \ - lock.c mutex.c proc.c sem.c bar.c time.c fortran.c affinity.c + lock.c mutex.c proc.c sem.c bar.c time.c fortran.c affinity.c \ + stream.c nodist_noinst_HEADERS = libgomp_f.h nodist_libsubinclude_HEADERS = omp.h diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in index bfc558c2e51..472241ab475 100644 --- a/libgomp/Makefile.in +++ b/libgomp/Makefile.in @@ -82,7 +82,7 @@ libgomp_la_LIBADD = am_libgomp_la_OBJECTS = alloc.lo barrier.lo critical.lo env.lo \ error.lo iter.lo loop.lo ordered.lo parallel.lo sections.lo \ single.lo team.lo work.lo lock.lo mutex.lo proc.lo sem.lo \ - bar.lo time.lo fortran.lo affinity.lo + bar.lo time.lo fortran.lo affinity.lo stream.lo libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS) DEFAULT_INCLUDES = -I. -I$(srcdir) -I. depcomp = $(SHELL) $(top_srcdir)/../depcomp @@ -291,7 +291,8 @@ libgomp_version_info = -version-info $(libtool_VERSION) libgomp_la_LDFLAGS = $(libgomp_version_info) $(libgomp_version_script) libgomp_la_SOURCES = alloc.c barrier.c critical.c env.c error.c iter.c \ loop.c ordered.c parallel.c sections.c single.c team.c work.c \ - lock.c mutex.c proc.c sem.c bar.c time.c fortran.c affinity.c + lock.c mutex.c proc.c sem.c bar.c time.c fortran.c affinity.c \ + stream.c nodist_noinst_HEADERS = libgomp_f.h nodist_libsubinclude_HEADERS = omp.h @@ -436,6 +437,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sections.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sem.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/single.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/team.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/time.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/work.Plo@am__quote@ diff --git a/libgomp/libgomp.h b/libgomp/libgomp.h index 7075250a87f..d2d057c4110 100644 --- a/libgomp/libgomp.h +++ b/libgomp/libgomp.h @@ -218,6 +218,29 @@ struct gomp_thread gomp_sem_t release; }; +/* This structure represents a stream between tasks. */ + +typedef struct gomp_stream +{ + /* End of stream: true when producer has finished inserting elements. */ + bool eos_p; + + /* First element of the stream. */ + unsigned first; + + /* First empty element of the stream. */ + unsigned last; + + /* Size in bytes of an element in the stream. */ + size_t size; + + /* Size in bytes of the circular buffer. */ + unsigned count; + + /* Circular buffer. */ + char *buffer; +} *gomp_stream; + /* ... and here is that TLS data. */ #ifdef HAVE_TLS @@ -304,6 +327,19 @@ extern unsigned gomp_resolve_num_threads (unsigned); extern void gomp_init_num_threads (void); extern unsigned gomp_dynamic_max_threads (void); +/* stream.c */ + +gomp_stream gomp_stream_create (size_t, unsigned); +unsigned gomp_stream_used_space (gomp_stream); +unsigned gomp_stream_free_space (gomp_stream); +void gomp_stream_wait_used_space (gomp_stream, unsigned); +void gomp_stream_wait_free_space (gomp_stream, unsigned); +void gomp_stream_push (gomp_stream, void *); +void gomp_stream_pop (gomp_stream, void *); +bool gomp_stream_eos_p (gomp_stream); +void gomp_stream_set_eos (gomp_stream); +void gomp_stream_destroy (gomp_stream); + /* team.c */ extern void gomp_team_start (void (*) (void *), void *, unsigned, diff --git a/libgomp/stream.c b/libgomp/stream.c new file mode 100644 index 00000000000..a879ddb0cfa --- /dev/null +++ b/libgomp/stream.c @@ -0,0 +1,130 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + Contributed by Antoniu Pop <antoniu.pop@gmail.com> + and Sebastian Pop <sebastian.pop@amd.com>. + + This file is part of the GNU OpenMP Library (libgomp). + + Libgomp 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. + + Libgomp 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 for + more details. + + You should have received a copy of the GNU Lesser General Public License + along with libgomp; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. */ + +/* As a special exception, if you link this library with other files, some + of which are compiled with GCC, to produce an executable, this library + does not by itself cause the resulting executable to be covered by the + GNU General Public License. This exception does not however invalidate + any other reasons why the executable file might be covered by the GNU + General Public License. */ + +/* This file handles streams. */ + +#include "libgomp.h" +#include <stdlib.h> +#include <string.h> +#include <sched.h> + +/* Returns a new stream of COUNT elements of SIZE bytes. */ + +gomp_stream +gomp_stream_create (size_t size, unsigned count) +{ + gomp_stream res = (gomp_stream) gomp_malloc (sizeof (struct gomp_stream)); + + res->eos_p = false; + res->first = 0; + res->last = 0; + res->size = size; + res->count = count; + res->buffer = (char *) gomp_malloc (res->count * res->size); + + return res; +} + +/* Returns the number of used elements in the stream S. */ + +unsigned +gomp_stream_used_space (gomp_stream s) +{ + return s->last - s->first; +} + +/* Returns the number of unused element slots available in the buffer + of the stream S. */ + +unsigned +gomp_stream_free_space (gomp_stream s) +{ + return s->count - (s->last - s->first); +} + +/* Wait until the number of elements in the stream S reaches COUNT. */ + +void +gomp_stream_wait_used_space (gomp_stream s, unsigned count) +{ + while (gomp_stream_used_space (s) < count) + sched_yield (); +} + +/* Wait until the available space in the stream S reaches COUNT. */ + +void +gomp_stream_wait_free_space (gomp_stream s, unsigned count) +{ + while (gomp_stream_free_space (s) < count) + sched_yield (); +} + +/* Push element ELT to stream S. */ + +void +gomp_stream_push (gomp_stream s, void *elt) +{ + gomp_stream_wait_free_space (s, 1); + memcpy (&(s->buffer[s->last]), elt, s->size); + s->last = (s->last + 1) % s->count; +} + +/* Returns in RES the first element of the stream S. */ + +void +gomp_stream_pop (gomp_stream s, void *res) +{ + gomp_stream_wait_used_space (s, 1); + memcpy (res, &(s->buffer[s->first]), s->size); + s->first = (s->first + 1) % s->count; +} + +/* Returns true when producer stopped to write to stream S. */ + +bool +gomp_stream_eos_p (gomp_stream s) +{ + return s->eos_p; +} + +/* Producer can set End Of Stream to stream S. */ + +void +gomp_stream_set_eos (gomp_stream s) +{ + s->eos_p = true; +} + +/* Free stream S. */ + +void +gomp_stream_destroy (gomp_stream s) +{ + free (s); +} |