Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Reworked back end handlers. debug is now always there and all abck en…

…d has a runtime component accessible through the whole system.
  • Loading branch information...
commit ce0a7620dce0182eb0b59584f7533ac095a0e641 1 parent cbbed49
@jfalcou authored
Showing with 617 additions and 226 deletions.
  1. +20 −0 include/quaff/core/backend.hpp
  2. +33 −0 include/quaff/core/backend/backend.hpp
  3. +22 −4 include/quaff/core/backend/debug/backend.hpp
  4. +4 −1 include/quaff/core/backend/debug/instructions/call.hpp
  5. +2 −1  include/quaff/core/backend/instructions.hpp
  6. +28 −9 include/quaff/core/backend/sequential/backend.hpp
  7. +15 −4 include/quaff/core/backend/sequential/instructions/call.hpp
  8. +86 −0 include/quaff/core/dsl/semantic.hpp
  9. +23 −2 include/quaff/core/models/process_network.hpp
  10. +1 −1  include/quaff/core/models/process_network/descriptor.hpp
  11. +53 −0 include/quaff/core/models/process_network/empty.hpp
  12. +42 −55 include/quaff/core/models/process_network/environment.hpp
  13. +57 −0 include/quaff/core/models/process_network/forward.hpp
  14. +54 −23 include/quaff/core/models/process_network/joint_network.hpp
  15. +31 −42 include/quaff/core/models/process_network/network.hpp
  16. +19 −12 include/quaff/core/models/process_network/process.hpp
  17. +30 −10 include/quaff/core/models/process_network/semantic/rule_pardo.hpp
  18. +51 −34 include/quaff/core/models/process_network/semantic/rule_seq.hpp
  19. +31 −28 include/quaff/core/models/process_network/transform.hpp
  20. +15 −0 src/core/backend.cpp
View
20 include/quaff/core/backend.hpp
@@ -0,0 +1,20 @@
+/******************************************************************************
+ * Copyright 2003 & onward LASMEA UMR 6602 CNRS/Univ. Clermont II
+ * Copyright 2007 & onward IEF UMR 8622 CNRS/Univ Paris Sud XI
+ * Copyright 2008 & onward LRI UMR 8623 CNRS/Univ Paris Sud XI
+ *
+ * Distributed under the Boost Software License, Version 1.0.
+ * See accompanying file LICENSE.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt
+ ******************************************************************************/
+#ifndef QUAFF_CORE_BACKEND_HPP_INCLUDED
+#define QUAFF_CORE_BACKEND_HPP_INCLUDED
+
+////////////////////////////////////////////////////////////////////////////////
+/// @file quaff/core/backend.hpp
+////////////////////////////////////////////////////////////////////////////////
+#include <quaff/core/models/process_network.hpp>
+#include <quaff/core/backend/backend.hpp>
+
+
+#endif
View
33 include/quaff/core/backend/backend.hpp
@@ -0,0 +1,33 @@
+/******************************************************************************
+ * Copyright 2003 & onward LASMEA UMR 6602 CNRS/Univ. Clermont II
+ * Copyright 2007 & onward IEF UMR 8622 CNRS/Univ Paris Sud XI
+ * Copyright 2008 & onward LRI UMR 8623 CNRS/Univ Paris Sud XI
+ *
+ * Distributed under the Boost Software License, Version 1.0.
+ * See accompanying file LICENSE.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt
+ ******************************************************************************/
+#ifndef QUAFF_CORE_BACKEND_BACKEND_HPP_INCLUDED
+#define QUAFF_CORE_BACKEND_BACKEND_HPP_INCLUDED
+
+////////////////////////////////////////////////////////////////////////////////
+/// @file quaff/core/backend/backend.hpp
+////////////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////////////
+// the text debug back-end is always available
+////////////////////////////////////////////////////////////////////////////////
+#include <quaff/core/backend/debug/backend.hpp>
+
+#if defined(QUAFF_TARGET_MPI)
+#else
+#include <quaff/core/backend/sequential/backend.hpp>
+#endif
+
+namespace quaff
+{
+ inline void start() { current_backend.start(); }
+ inline void terminate() { current_backend.terminate(); }
+}
+
+#endif
View
26 include/quaff/core/backend/debug/backend.hpp
@@ -17,17 +17,23 @@ namespace quaff { namespace backend
{
struct debug_
{
+ void terminate() {}
+ void start() {}
+
// How to run a network
- template<class N> void run_network( N const& n )
+ template<class Network> void accept( Network const& n )
{
boost::fusion::for_each(n.nodes(),runner(*this));
}
+
// How to run a process
- template<class Proc> void run_process(Proc const& p)
+ template<class Proc> void run(Proc const& p)
{
+ typename Proc::input_type ins;
+ typename Proc::output_type outs;
std::cout << "[ Running process " << Proc::pid_type::value << "]\n";
- p.code()();
+ p(ins,outs);
std::cout << "[-------------------------------]\n";
}
@@ -36,11 +42,23 @@ namespace quaff { namespace backend
{
debug_& be;
runner(debug_& b) :be(b) {}
- template<class P> void operator()(P& proc) const { proc(be); }
+ template<class P> void operator()(P& proc) const { be.run(proc); }
};
};
} }
+////////////////////////////////////////////////////////////////////////////////
+// Generate a debug on the standard output
+////////////////////////////////////////////////////////////////////////////////
+template<class X> void debug(X const& xpr)
+{
+ quaff::semantic::convert<quaff::tag::process_network_> converter;
+ quaff::model::empty_environment env;
+ quaff::backend::debug_ target;
+
+ converter( xpr, env, target ).network().run(target);
+}
+
#include <quaff/core/backend/debug/instructions/call.hpp>
#endif
View
5 include/quaff/core/backend/debug/instructions/call.hpp
@@ -19,9 +19,12 @@ namespace quaff { namespace instruction
template<class Function>
struct call<Function,backend::debug_>
{
+ typedef typename Function::input_type input_type;
+ typedef typename Function::output_type output_type;
+
call(Function const& f) : mFunction(f) {}
- void operator()() const
+ void operator()(input_type const&, output_type& ) const
{
std::cout << "| CALL " << (void*)(&mFunction) << "\n";
}
View
3  include/quaff/core/backend/instructions.hpp
@@ -16,7 +16,8 @@
namespace quaff { namespace instruction
{
- template<class Function,class BackEnd> struct call;
+ template<class Function,class BackEnd> struct call;
+ template<class F1, class F2,class BackEnd> struct compose;
} }
#endif
View
37 include/quaff/core/backend/sequential/backend.hpp
@@ -18,33 +18,52 @@ namespace quaff { namespace backend
{
struct sequential_
{
+ sequential_() { start(); }
+
+ void terminate() { status_ = false; }
+ void start() { status_ = true; }
+
+ bool status_;
+
// How to run a network
- template<class N> void run_network( N const& n )
+ template<class Network> void accept( Network const& n )
{
boost::fusion::for_each(n.nodes(),runner(*this));
}
// How to run a process
- template<class Proc> void run_process(Proc const& p)
+ template<class Proc> void run(Proc const& p)
{
- // Geenerate data
- //do
+ start();
+
+ // Generate data
+ typename Proc::input_type ins;
+ typename Proc::output_type outs;
+
+ do
{
- // Run code till their are invalid
- p.code()(); //(args,back_end);
- } //while( is_running() );
+ p(ins,outs);
+ }
+ while( status_ );
}
// Some helpers
struct runner
{
sequential_& be;
- runner(sequential_& b) :be(b) {}
- template<class P> void operator()(P& proc) const { proc(be); }
+ runner(sequential_& b) : be(b) {}
+ template<class P> void operator()(P& proc) const { be.run(proc); }
};
};
} }
+namespace quaff
+{
+ typedef backend::sequential_ current_backend_type;
+
+ extern current_backend_type current_backend;
+}
+
#include <quaff/core/backend/sequential/instructions/call.hpp>
#endif
View
19 include/quaff/core/backend/sequential/instructions/call.hpp
@@ -13,17 +13,28 @@
////////////////////////////////////////////////////////////////////////////////
/// @file quaff/core/backend/debug/instructions/call.hpp
////////////////////////////////////////////////////////////////////////////////
+#include <quaff/core/skeleton/source.hpp>
namespace quaff { namespace instruction
{
+ //////////////////////////////////////////////////////////////////////////////
+ // call a function within proper interface
+ //////////////////////////////////////////////////////////////////////////////
template<class Function>
struct call<Function,backend::sequential_>
- {
- call(Function const& f) : mFunction(f) {}
+ {
+ typedef typename Function::input_type input_type;
+ typedef typename Function::output_type output_type;
- void operator()() const { mFunction(); }
+ call(Function const& f)
+ : function_(f) {}
- Function mFunction;
+ void operator()(input_type const& ins, output_type& outs) const
+ {
+ outs = function_(ins);
+ }
+
+ Function function_;
};
} }
View
86 include/quaff/core/dsl/semantic.hpp
@@ -0,0 +1,86 @@
+/******************************************************************************
+ * Copyright 2003 & onward LASMEA UMR 6602 CNRS/Univ. Clermont II
+ * Copyright 2007 & onward IEF UMR 8622 CNRS/Univ Paris Sud XI
+ * Copyright 2008 & onward LRI UMR 8623 CNRS/Univ Paris Sud XI
+ *
+ * Distributed under the Boost Software License, Version 1.0.
+ * See accompanying file LICENSE.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt
+ ******************************************************************************/
+#ifndef QUAFF_CORE_DSL_SEMANTIC_HPP_INCLUDED
+#define QUAFF_CORE_DSL_SEMANTIC_HPP_INCLUDED
+
+#include <boost/proto/proto.hpp>
+
+////////////////////////////////////////////////////////////////////////////////
+// Model forward declaration for process networks semantic rules
+////////////////////////////////////////////////////////////////////////////////
+namespace quaff { namespace semantic
+{
+ //////////////////////////////////////////////////////////////////////////////
+ // Generic Transform eating up an ASt and outputing an environment of Model
+ //////////////////////////////////////////////////////////////////////////////
+ template<class Model> struct convert;
+
+ //////////////////////////////////////////////////////////////////////////////
+ // Rule for converting Seq(F) to a proper environment
+ //////////////////////////////////////////////////////////////////////////////
+ template<class Model> struct convert_seq;
+
+ //////////////////////////////////////////////////////////////////////////////
+ // Rule for converting (F1,F2) to a proper environment
+ //////////////////////////////////////////////////////////////////////////////
+ template<class Model> struct convert_chain;
+
+ //////////////////////////////////////////////////////////////////////////////
+ // Rule for converting (S1 & S2) to a proper environment
+ //////////////////////////////////////////////////////////////////////////////
+ template<class Model> struct convert_pardo;
+
+ //////////////////////////////////////////////////////////////////////////////
+ // Rule for converting (S1 | S2) to a proper environment
+ //////////////////////////////////////////////////////////////////////////////
+ template<class Model> struct convert_pipe;
+
+ //////////////////////////////////////////////////////////////////////////////
+ // Rule for converting map(F) to a proper environment
+ //////////////////////////////////////////////////////////////////////////////
+ template<class Model> struct convert_map;
+
+ //////////////////////////////////////////////////////////////////////////////
+ // Rule for converting farm(S) to a proper environment
+ //////////////////////////////////////////////////////////////////////////////
+ template<class Model> struct convert_farm;
+} }
+
+////////////////////////////////////////////////////////////////////////////////
+// Register all semantic rules as proto transform
+////////////////////////////////////////////////////////////////////////////////
+namespace boost { namespace proto
+{
+ template<class Model>
+ struct is_callable< quaff::semantic::convert_seq<Model> >
+ : mpl::true_ {};
+
+ template<class Model>
+ struct is_callable< quaff::semantic::convert_chain<Model> >
+ : mpl::true_ {};
+
+ template<class Model>
+ struct is_callable< quaff::semantic::convert_pardo<Model> >
+ : mpl::true_ {};
+
+ template<class Model>
+ struct is_callable< quaff::semantic::convert_pipe<Model> >
+ : mpl::true_ {};
+
+ template<class Model>
+ struct is_callable< quaff::semantic::convert_map<Model> >
+ : mpl::true_ {};
+
+ template<class Model>
+ struct is_callable< quaff::semantic::convert_farm<Model> >
+ : mpl::true_ {};
+} }
+
+#endif
View
25 include/quaff/core/models/process_network.hpp
@@ -10,9 +10,30 @@
#ifndef QUAFF_CORE_MODELS_PROCESS_NETWORK_HPP_INCLUDED
#define QUAFF_CORE_MODELS_PROCESS_NETWORK_HPP_INCLUDED
+////////////////////////////////////////////////////////////////////////////////
+// This file defines the process network based intermediate representation
+////////////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////////////
+// Tag markup for identifying current model
+////////////////////////////////////////////////////////////////////////////////
+namespace quaff { namespace tag { struct process_network_ {}; } }
+
+////////////////////////////////////////////////////////////////////////////////
+// Model forward declaration and entities
+////////////////////////////////////////////////////////////////////////////////
+#include <quaff/core/models/process_network/forward.hpp>
+#include <quaff/core/models/process_network/environment.hpp>
#include <quaff/core/models/process_network/network.hpp>
-#include <quaff/core/models/process_network/join_network.hpp>
+#include <quaff/core/models/process_network/joint_network.hpp>
#include <quaff/core/models/process_network/process.hpp>
-#include <quaff/core/models/process_network/descriptor.hpp>
+#include <quaff/core/models/process_network/empty.hpp>
+
+////////////////////////////////////////////////////////////////////////////////
+// Model semantic rules
+////////////////////////////////////////////////////////////////////////////////
+#include <quaff/core/models/process_network/transform.hpp>
+#include <quaff/core/models/process_network/semantic/rule_seq.hpp>
+#include <quaff/core/models/process_network/semantic/rule_pardo.hpp>
#endif
View
2  include/quaff/core/models/process_network/descriptor.hpp
@@ -28,7 +28,7 @@ namespace quaff { namespace model
void operator()() const
{
- boost::fusion::at_c<0>(codelet)();
+ codelet();
//*out = codelet( *in );
}
View
53 include/quaff/core/models/process_network/empty.hpp
@@ -0,0 +1,53 @@
+/******************************************************************************
+ * Copyright 2003 & onward LASMEA UMR 6602 CNRS/Univ. Clermont II
+ * Copyright 2007 & onward IEF UMR 8622 CNRS/Univ Paris Sud XI
+ * Copyright 2008 & onward LRI UMR 8623 CNRS/Univ Paris Sud XI
+ *
+ * Distributed under the Boost Software License, Version 1.0.
+ * See accompanying file LICENSE.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt
+ ******************************************************************************/
+#ifndef QUAFF_CORE_MODELS_PROCESS_NETWORK_EMPTY_HPP_INCLUDED
+#define QUAFF_CORE_MODELS_PROCESS_NETWORK_EMPTY_HPP_INCLUDED
+
+////////////////////////////////////////////////////////////////////////////////
+// Empty environment and network class
+////////////////////////////////////////////////////////////////////////////////
+namespace quaff { namespace model
+{
+ //////////////////////////////////////////////////////////////////////////////
+ /// empty process network - to be used in process network transform
+ //////////////////////////////////////////////////////////////////////////////
+ template<>
+ struct network< boost::fusion::vector<>
+ , boost::mpl::set<> , boost::mpl::set<>
+ , boost::mpl::void_ , boost::mpl::void_
+ >
+ {
+ typedef boost::fusion::vector<> processes;
+ typedef boost::mpl::set<> inputs;
+ typedef boost::mpl::set<> outputs;
+ };
+
+ typedef network < boost::fusion::vector<>
+ , boost::mpl::set<> , boost::mpl::set<>
+ , boost::mpl::void_ , boost::mpl::void_
+ >
+ empty_network;
+
+ //////////////////////////////////////////////////////////////////////////////
+ // Specialisation for empty environment
+ //////////////////////////////////////////////////////////////////////////////
+ template<> struct environment<empty_network, boost::mpl::int_<0> >
+ {
+ typedef empty_network network_type;
+ typedef boost::mpl::int_<0> pid_type;
+
+ network_type network() const { return network_type(); }
+ pid_type pid() const { return pid_type(); }
+ };
+
+ typedef environment<empty_network, boost::mpl::int_<0> > empty_environment;
+} }
+
+#endif
View
97 include/quaff/core/models/process_network/environment.hpp
@@ -15,79 +15,66 @@
////////////////////////////////////////////////////////////////////////////////
#include <boost/proto/proto.hpp>
#include <boost/mpl/next_prior.hpp>
-#include <quaff/core/models/process_network/network.hpp>
namespace quaff { namespace model
{
- /*****************************************************************************
- * environment gathers network and current PID value inside proto transforms
- ****************************************************************************/
- template<class Network, class PID>
+ //////////////////////////////////////////////////////////////////////////////
+ // environment is used to capture required element of the IR while being built
+ //////////////////////////////////////////////////////////////////////////////
+ template< class Network
+ , class PIDState
+ >
struct environment
{
- typedef Network network_type;
- typedef PID pid_type;
+ typedef Network network_type;
+ typedef PIDState pid_type;
- environment(Network const& n) : network_(n) {}
+ ////////////////////////////////////////////////////////////////////////////
+ // Build an environnement from a network and a back-end
+ ////////////////////////////////////////////////////////////////////////////
+ environment ( network_type const& n ) : network_(n) {}
- template<class BackEnd> void operator()(BackEnd& be) const
- {
- network_(be);
- }
-
- Network const& network() const { return network_; }
- pid_type pid() const { return pid_type(); }
+ ////////////////////////////////////////////////////////////////////////////
+ // Access to environment components
+ ////////////////////////////////////////////////////////////////////////////
+ network_type const& network() const { return network_; }
+ pid_type next_pid() const { return pid_type(); }
- Network network_;
+ network_type network_;
};
- /*****************************************************************************
- * Build an environnement out of its component
- ****************************************************************************/
+ //////////////////////////////////////////////////////////////////////////////
+ // Build an environnement from Network and PID
+ //////////////////////////////////////////////////////////////////////////////
template<class PID,class Network>
- environment<Network,PID> make_environment(Network const& n, PID const&)
+ inline environment<Network,PID> make_environment(Network const& n, PID const&)
{
environment<Network,PID> that(n);
return that;
}
-
- /*****************************************************************************
- * specialisation for empty environment
- ****************************************************************************/
- template<> struct environment<empty_network, boost::mpl::int_<0> >
- {
- typedef empty_network network_type;
- typedef boost::mpl::int_<0> pid_type;
-
- network_type network() const { return network_type(); }
- pid_type pid() const { return pid_type(); }
-
- };
-
- /*****************************************************************************
- * proto transforms retrieving the current pid of an environment
- ****************************************************************************/
- struct pid_ : boost::proto::callable
- {
- template<class Sig> struct result;
- template<class This, class Env>
- struct result<This(Env)>
- {
- typedef typename boost::proto::detail::uncvref<Env>::type base;
- typedef typename base::pid_type type;
- };
+ //////////////////////////////////////////////////////////////////////////////
+ // proto transforms retrieving the current pid of an environment
+ //////////////////////////////////////////////////////////////////////////////
+ struct pid_ : boost::proto::callable
+ {
+ template<class Sig> struct result;
- template<class Env> inline
- typename result<pid_(Env const&)>::type
- operator()(Env const& ) const
- {
- typename result<pid_(Env const&)>::type that;
- return that;
- }
- };
+ template<class This, class Env>
+ struct result<This(Env)>
+ {
+ typedef typename boost::proto::detail::uncvref<Env>::type base;
+ typedef typename base::pid_type type;
+ };
- typedef environment<empty_network, boost::mpl::int_<0> > empty_environment;
+ template<class Env> inline
+ typename result<pid_(Env const&)>::type
+ operator()(Env const& ) const
+ {
+ typename result<pid_(Env const&)>::type that;
+ return that;
+ }
+ };
} }
#endif
View
57 include/quaff/core/models/process_network/forward.hpp
@@ -0,0 +1,57 @@
+/******************************************************************************
+ * Copyright 2003 & onward LASMEA UMR 6602 CNRS/Univ. Clermont II
+ * Copyright 2007 & onward IEF UMR 8622 CNRS/Univ Paris Sud XI
+ * Copyright 2008 & onward LRI UMR 8623 CNRS/Univ Paris Sud XI
+ *
+ * Distributed under the Boost Software License, Version 1.0.
+ * See accompanying file LICENSE.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt
+ ******************************************************************************/
+#ifndef QUAFF_CORE_MODELS_PROCESS_NETWORK_FORWARD_HPP_INCLUDED
+#define QUAFF_CORE_MODELS_PROCESS_NETWORK_FORWARD_HPP_INCLUDED
+
+////////////////////////////////////////////////////////////////////////////////
+// Model forward declaration for process networks
+////////////////////////////////////////////////////////////////////////////////
+namespace quaff { namespace model
+{
+ template<class Network, class PIDState> struct environment;
+
+ template< class Nodes
+ , class InputSet , class OutputSet
+ , class InputTypes , class OutputTypes
+ >
+ struct network;
+
+ //////////////////////////////////////////////////////////////////////////////
+ // a joint_network is the union of two other Network used in some skeleton
+ // to simplify the building of the intermediate representation.
+ //
+ // joint_network models the network concept.
+ //////////////////////////////////////////////////////////////////////////////
+ template<class Network1,class Network2> struct joint_network;
+
+ //////////////////////////////////////////////////////////////////////////////
+ // Process is a concept around PID-localizable code fragment. Depending on
+ // Backend, this code fragment may be parallel or not
+ //////////////////////////////////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////////////////////////////////
+ // a process is built from a :
+ // - a PID which is a pair of IntegralConstant holding the range of PID on
+ // which the actual process code can be executed
+ // - a CodeFragment which is a Deferred Calalble Object containing the code
+ // fragment ot be executed
+ // - an input Type
+ // - an output Type
+ //
+ // process also acts as unary Deferred Callable Object
+ //////////////////////////////////////////////////////////////////////////////
+ template< class PIDRange
+ , class CodeFragment
+ , class InputType, class OutputType
+ >
+ struct process;
+} }
+
+#endif
View
77 include/quaff/core/models/process_network/joint_network.hpp
@@ -7,52 +7,83 @@
* See accompanying file LICENSE.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt
******************************************************************************/
-#ifndef QUAFF_CORE_MODELS_PROCESS_NETWORK_JOIN_NETWORK_HPP_INCLUDED
-#define QUAFF_CORE_MODELS_PROCESS_NETWORK_JOIN_NETWORK_HPP_INCLUDED
+#ifndef QUAFF_CORE_MODELS_PROCESS_NETWORK_JOINT_NETWORK_HPP_INCLUDED
+#define QUAFF_CORE_MODELS_PROCESS_NETWORK_JOINT_NETWORK_HPP_INCLUDED
////////////////////////////////////////////////////////////////////////////////
/// @file quaff/core/models/process_network/join_network.hpp
////////////////////////////////////////////////////////////////////////////////
-#include <boost/mpl/vector.hpp>
+#include <quaff/sdk/type_id.hpp>
#include <boost/fusion/include/vector.hpp>
-#include <boost/fusion/include/for_each.hpp>
-#include <boost/fusion/include/at.hpp>
#include <boost/fusion/include/joint_view.hpp>
+#include <boost/fusion/include/vector_tie.hpp>
namespace quaff { namespace model
{
//////////////////////////////////////////////////////////////////////////////
- ///joint network structure
- /// Static datatype representing the union of two process networks.
+ // joint network structure
+ // Static datatype representing the union of two process networks.
//////////////////////////////////////////////////////////////////////////////
template<class Network1,class Network2>
struct joint_network
{
- typedef boost::fusion::joint_view< typename Network1::processes
- , typename Network2::processes
- > processes;
-
-
- typedef boost::fusion::joint_view< typename Network1::inputs
- , typename Network2::inputs
- > inputs;
+ ////////////////////////////////////////////////////////////////////////////
+ // nodes, input and output set of a joint network is the joint view
+ // of the underlying sequence of both original networks
+ ////////////////////////////////////////////////////////////////////////////
+ typedef boost::fusion::joint_view< typename Network1::nodes_type const
+ , typename Network2::nodes_type const
+ > nodes_type;
+ typedef boost::fusion::joint_view< typename Network1::input_set
+ , typename Network2::input_set
+ > input_set;
- typedef boost::fusion::joint_view< typename Network1::outputs
- , typename Network2::outputs
- > outputs;
+ typedef boost::fusion::joint_view< typename Network1::output_set
+ , typename Network2::output_set
+ > output_set;
+ typedef boost::fusion::vector < typename Network1::input_type
+ , typename Network2::input_type
+ > input_type;
+
+ typedef boost::fusion::vector < typename Network1::output_type
+ , typename Network2::output_type
+ > output_type;
+
+ ////////////////////////////////////////////////////////////////////////////
+ // Build a joint network from two other Networks
+ ////////////////////////////////////////////////////////////////////////////
joint_network ( Network1 const& n1, Network2 const& n2 )
: nodes1(n1), nodes2(n2)
{}
////////////////////////////////////////////////////////////////////////////
- // Run each process in a process network using for_each.
+ // Pass current network to a Back-End
+ ////////////////////////////////////////////////////////////////////////////
+ template<class BackEnd> void run(BackEnd& be) const
+ {
+ // The BackEnd acts like a Visitor over the network
+ be.accept(nodes1);
+ be.accept(nodes2);
+ }
+
+ ////////////////////////////////////////////////////////////////////////////
+ // Acces to the network Nodes sequence
////////////////////////////////////////////////////////////////////////////
- template<class BackEnd> void operator()(BackEnd& be) const
- {
- nodes1(be);
- nodes2(be);
+ boost::fusion::
+ joint_view< typename Network1::nodes_type const
+ , typename Network2::nodes_type const
+ > const
+ nodes() const
+ {
+ boost::fusion::
+ joint_view< typename Network1::nodes_type const
+ , typename Network2::nodes_type const
+ > const
+ that(nodes1.nodes(),nodes2.nodes()) ;
+
+ return that;
}
Network1 nodes1;
View
73 include/quaff/core/models/process_network/network.hpp
@@ -22,66 +22,55 @@
namespace quaff { namespace model
{
//////////////////////////////////////////////////////////////////////////////
- ///network structure
- ///
- /// Static datatype representing a process network. In this representation,
- /// a process network is defined by a triplet <P,I,O>:
- /// - Process : a list of processus
- /// - InputNodes : a list of input nodes
- /// - OutputNodes : a list of outputs node
+ // a network is built from a:
+ // - a FusionRandomAccessSequence of process (usually a fusion::vector)
+ // - a MetaAssociativeSequence of input and output nodes (usually a mpl::set)
+ // - an input Type
+ // - an output Type
//////////////////////////////////////////////////////////////////////////////
- template<class Processes,class InputNodes,class OutputNodes>
+ template< class Nodes
+ , class InputSet , class OutputSet
+ , class InputTypes, class OutputTypes
+ >
struct network
{
- typedef Processes processes;
- typedef InputNodes inputs;
- typedef OutputNodes outputs;
+ typedef Nodes nodes_type;
+ typedef InputSet input_set;
+ typedef OutputSet output_set;
+ typedef InputTypes input_type;
+ typedef OutputTypes output_type;
- network(Processes const& n) : nodes_(n) {}
+ ////////////////////////////////////////////////////////////////////////////
+ // Build a network form its Nodes sequence
+ ////////////////////////////////////////////////////////////////////////////
+ network(nodes_type const& n) : nodes_(n) {}
////////////////////////////////////////////////////////////////////////////
- // Run each process in a process network using for_each.
+ // Pass current network to a Back-End
////////////////////////////////////////////////////////////////////////////
- template<class BackEnd> void operator()(BackEnd& be) const
+ template<class BackEnd> void run(BackEnd& be) const
{
- be.run_network(*this);
+ // The BackEnd acts like a Visitor over the network
+ be.accept(*this);
}
-
- struct runner
- {
- template<class P> void operator()(P& proc) const { proc(); }
- };
-
- Processes const& nodes() const { return nodes_; }
- Processes nodes_;
+ ////////////////////////////////////////////////////////////////////////////
+ // Acces to the network Nodes sequence
+ ////////////////////////////////////////////////////////////////////////////
+ nodes_type const& nodes() const { return nodes_; }
+
+ nodes_type nodes_;
};
//////////////////////////////////////////////////////////////////////////////
// Build a network out of its components
//////////////////////////////////////////////////////////////////////////////
- template<class P, class I,class O>
- network<P,I,O> make_network( P const& n, I const&, O const& )
+ template<class IT, class OT, class P, class I,class O>
+ network<P,I,O,IT,OT> make_network( P const& n, I const&, O const& )
{
- network<P,I,O> that(n);
+ network<P,I,O,IT,OT> that(n);
return that;
}
-
- //////////////////////////////////////////////////////////////////////////////
- /// empty process network - to be used in process network transform
- //////////////////////////////////////////////////////////////////////////////
- template<>
- struct network<boost::fusion::vector<>, boost::mpl::set<>, boost::mpl::set<> >
- {
- typedef boost::fusion::vector<> processes;
- typedef boost::mpl::set<> inputs;
- typedef boost::mpl::set<> outputs;
- };
-
- typedef network< boost::fusion::vector<>
- , boost::mpl::set<>
- , boost::mpl::set<>
- > empty_network;
} }
#endif
View
31 include/quaff/core/models/process_network/process.hpp
@@ -24,27 +24,34 @@ namespace quaff { namespace model
// - a process code Descriptor
// - an execution BackEnd
/////////////////////////////////////////////////////////////////////////////
- template<class Pid,class Descriptor,class BackEnd> struct process
+ template< class PIDRange
+ , class CodeFragment
+ , class InputType, class OutputType
+ >
+ struct process
{
- typedef Pid pid_type;
- typedef Descriptor descriptor_type;
+ typedef PIDRange pid_type;
+ typedef CodeFragment codelet_type;
+ typedef InputType input_type;
+ typedef OutputType output_type;
- process(Descriptor const& d) : code_(d) {}
+ process(codelet_type const& codelet) : codelet_(codelet) {}
+
+ void operator()(input_type const& in, output_type& out) const
+ {
+ codelet_(in,out);
+ }
- void operator()(BackEnd& be) const { be.run_process(*this); }
-
- Descriptor const& code() const { return code_; }
-
- Descriptor code_;
+ codelet_type codelet_;
};
//////////////////////////////////////////////////////////////////////////////
// Build a process out of its components
//////////////////////////////////////////////////////////////////////////////
- template<class PID,class D,class BE>
- process<PID,D,BE> make_process( PID const&, D const& d, BE const& )
+ template<class I, class O, class P,class C>
+ process<P,C,I,O> make_process( P const&, C const& c )
{
- process<PID,D,BE> that(d);
+ process<P,C,I,O> that(c);
return that;
}
} }
View
40 include/quaff/core/models/process_network/semantic/rule_pardo.hpp
@@ -13,18 +13,37 @@
////////////////////////////////////////////////////////////////////////////////
/// @file quaff/core/models/process_network/semantic/environment.hpp
////////////////////////////////////////////////////////////////////////////////
-#include <boost/proto/proto.hpp>
-#include <quaff/core/models/process_network/join_network.hpp>
-#include <quaff/core/models/process_network/semantic/apply_rule.hpp>
+#include <quaff/core/models/process_network/joint_network.hpp>
////////////////////////////////////////////////////////////////////////////////
// The pardo_ skeleton build the union of two network
// Inputs : the LHS/RHS skeleton, current state adn target back-end
// Outputs : an environment E = { build(LHS) U build(RHS) }
////////////////////////////////////////////////////////////////////////////////
-namespace quaff { namespace model
+namespace quaff { namespace semantic
{
- struct convert_pardo : boost::proto::callable
+ //////////////////////////////////////////////////////////////////////////////
+ // Handle seq node in the process_network IR
+ //////////////////////////////////////////////////////////////////////////////
+ template<>
+ struct process_network_cases::case_<boost::proto::tag::bitwise_and>
+ : boost::proto::
+ when< boost::proto::bitwise_and < boost::proto::_
+ , boost::proto::_
+ >
+ , convert_pardo<tag::process_network_>
+ ( boost::proto::_left
+ , boost::proto::_right
+ , boost::proto::_state
+ , boost::proto::_data
+ )
+ >
+ {};
+} }
+
+namespace quaff { namespace semantic
+{
+ template<> struct convert_pardo<tag::process_network_>
{
template<class Sig> struct result;
@@ -38,15 +57,16 @@ namespace quaff { namespace model
static lhs& lhs_; static rhs& rhs_;
static state& st; static back_end& be;
+ static convert<tag::process_network_>& converter;
// "temporary" environments
BOOST_TYPEOF_NESTED_TYPEDEF_TPL ( elhs
- , build_network()(lhs_,st,be)
+ , converter(lhs_,st,be)
);
static typename elhs::type& elhs_;
BOOST_TYPEOF_NESTED_TYPEDEF_TPL ( erhs
- , build_network()( rhs_, elhs_, be)
+ , converter( rhs_, elhs_, be)
);
static typename erhs::type& erhs_;
@@ -57,7 +77,7 @@ namespace quaff { namespace model
( join_network( elhs_.network()
, erhs_.network()
)
- , erhs_.pid()
+ , erhs_.next_pid()
)
);
@@ -68,14 +88,14 @@ namespace quaff { namespace model
typename result<convert_pardo(LHS, RHS, State, BackEnd)>::type
operator()(LHS const& lhs, RHS const& rhs, State& s, BackEnd const& be) const
{
- build_network callee;
+ convert<tag::process_network_> callee;
// Pre-compute environment to not copy it twice
BOOST_AUTO(lhe, callee(lhs,s,be) );
BOOST_AUTO(rhe, callee(rhs,lhe,be));
return make_environment ( join_network(lhe.network(),rhe.network())
- , rhe.pid()
+ , rhe.next_pid()
);
}
};
View
85 include/quaff/core/models/process_network/semantic/rule_seq.hpp
@@ -14,12 +14,8 @@
/// @file quaff/core/models/process_network/semantic/environment.hpp
////////////////////////////////////////////////////////////////////////////////
#include <boost/mpl/set.hpp>
-#include <boost/proto/proto.hpp>
#include <boost/fusion/include/vector.hpp>
#include <boost/fusion/include/make_vector.hpp>
-#include <quaff/core/models/process_network/network.hpp>
-#include <quaff/core/models/process_network/process.hpp>
-#include <quaff/core/models/process_network/descriptor.hpp>
#include <quaff/core/backend/instructions.hpp>
////////////////////////////////////////////////////////////////////////////////
@@ -29,9 +25,30 @@
// Inputs : the current function object f , the current PID p
// Outputs : an environment containing f as the single process of the network
////////////////////////////////////////////////////////////////////////////////
-namespace quaff { namespace model
+namespace quaff { namespace semantic
{
- struct convert_seq : boost::proto::callable
+ //////////////////////////////////////////////////////////////////////////////
+ // Handle seq node in the process_network IR
+ //////////////////////////////////////////////////////////////////////////////
+ template<>
+ struct process_network_cases::case_<boost::proto::tag::terminal>
+ : boost::proto::
+ when< boost::proto::terminal<boost::proto::_>
+ , convert_seq<tag::process_network_>
+ ( boost::proto::_value
+ , model::pid_(boost::proto::_state)
+ , boost::proto::_data
+ )
+ >
+ {};
+} }
+
+namespace quaff { namespace semantic
+{
+ //////////////////////////////////////////////////////////////////////////////
+ // Conversion function
+ //////////////////////////////////////////////////////////////////////////////
+ template<> struct convert_seq<tag::process_network_>
{
template<class Sig> struct result;
@@ -42,25 +59,25 @@ namespace quaff { namespace model
typedef typename boost::proto::detail::uncvref<Pid>::type pid;
typedef typename boost::proto::detail::uncvref<BackEnd>::type back_end;
+ typedef typename function::input_type input_type;
+ typedef typename function::output_type output_type;
+
static instruction::call<function,back_end>& f_;
BOOST_TYPEOF_NESTED_TYPEDEF_TPL
( nested
- , make_environment
+ , model::make_environment
(
- make_network( boost::fusion::make_vector
- ( make_process
- ( pid()
- , make_descriptor ( boost::fusion::vector<>()
- , boost::fusion::vector<>()
- , boost::fusion::make_vector(f_)
- )
- , back_end()
- )
+ model::make_network< input_type
+ , output_type
+ > ( boost::fusion::make_vector
+ ( model::make_process< input_type
+ , output_type
+ >( pid(), f_ )
+ )
+ , boost::mpl::set<pid>()
+ , boost::mpl::set<pid>()
)
- , boost::mpl::set<pid>()
- , boost::mpl::set<pid>()
- )
, typename boost::mpl::next<pid>::type()
)
);
@@ -74,23 +91,23 @@ namespace quaff { namespace model
{
instruction::call<Function,BackEnd> f_(f);
+ typedef typename Function::input_type input_type;
+ typedef typename Function::output_type output_type;
+
return
- make_environment
+ model::make_environment
(
- make_network( boost::fusion::make_vector
- ( make_process
- ( pid
- , make_descriptor ( boost::fusion::vector<>()
- , boost::fusion::vector<>()
- , boost::fusion::make_vector(f_)
- )
- , be
- )
- )
- , boost::mpl::set<Pid>()
- , boost::mpl::set<Pid>()
- )
- , typename boost::mpl::next<Pid>::type()
+ model::make_network < input_type
+ , output_type
+ >
+ ( boost::fusion::make_vector
+ (
+ model::make_process<input_type, output_type>( pid, f_ )
+ )
+ , boost::mpl::set<Pid>()
+ , boost::mpl::set<Pid>()
+ )
+ , typename boost::mpl::next<Pid>::type()
);
}
};
View
59 include/quaff/core/models/process_network/transform.hpp
@@ -10,37 +10,40 @@
#ifndef QUAFF_CORE_MODELS_PROCESS_NETWORK_TRANSFORM_HPP_INCLUDED
#define QUAFF_CORE_MODELS_PROCESS_NETWORK_TRANSFORM_HPP_INCLUDED
-#include <quaff/core/models/process_network/network.hpp>
-#include <quaff/core/models/process_network/process.hpp>
-#include <quaff/core/models/process_network/descriptor.hpp>
-#include <quaff/core/models/process_network/semantic/environment.hpp>
-#include <quaff/core/models/process_network/semantic/apply_rule.hpp>
-#include <quaff/core/models/process_network/semantic/rule_seq.hpp>
-#include <quaff/core/models/process_network/semantic/rule_pardo.hpp>
+#include <quaff/core/dsl/semantic.hpp>
-namespace quaff { namespace model
+namespace quaff { namespace semantic
{
- struct build_network
- : boost::proto::
- or_ < boost::proto::
- when< boost::proto::terminal<boost::proto::_>
- , convert_seq ( boost::proto::_value
- , pid_(boost::proto::_state)
- , boost::proto::_data
- )
- >
- , boost::proto::
- when< boost::proto::bitwise_and < boost::proto::_
- , boost::proto::_
- >
- , convert_pardo ( boost::proto::_left
- , boost::proto::_right
- , boost::proto::_state
- , boost::proto::_data
- )
- >
- >
+ //////////////////////////////////////////////////////////////////////////////
+ // Switch table for the proto transform turnign a skeleton AST into a process
+ // network. This allow for external extension of skeleton set
+ //////////////////////////////////////////////////////////////////////////////
+ struct process_network_cases
+ {
+ template<typename Tag>
+ struct case_ : boost::proto::not_< boost::proto::_ >
+ {};
+ };
+
+ //////////////////////////////////////////////////////////////////////////////
+ // Generate a process network based IR
+ //////////////////////////////////////////////////////////////////////////////
+ template<>
+ struct convert< quaff::tag::process_network_ >
+ : boost::proto::switch_<process_network_cases>
{};
} }
+namespace boost { namespace proto
+{
+ //////////////////////////////////////////////////////////////////////////////
+ // convert is a callable transform
+ //////////////////////////////////////////////////////////////////////////////
+ template<>
+ struct is_callable < quaff::semantic::
+ convert<quaff::tag::process_network_>
+ >
+ : boost::mpl::true_ {};
+} }
+
#endif
View
15 src/core/backend.cpp
@@ -0,0 +1,15 @@
+/******************************************************************************
+ * Copyright 2003 & onward LASMEA UMR 6602 CNRS/Univ. Clermont II
+ * Copyright 2007 & onward IEF UMR 8622 CNRS/Univ Paris Sud XI
+ * Copyright 2008 & onward LRI UMR 8623 CNRS/Univ Paris Sud XI
+ *
+ * Distributed under the Boost Software License, Version 1.0.
+ * See accompanying file LICENSE.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt
+ ******************************************************************************/
+#include <quaff/core/backend.hpp>
+
+namespace quaff
+{
+ current_backend_type current_backend;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.