Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
las3_pub
/
predictable_parallel_patterns
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f374d93f
authored
Jul 10, 2019
by
FritzFlorian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Basic pushing of data through inputs/outputs.
parent
52d39102
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
94 additions
and
20 deletions
+94
-20
app/playground/main.cpp
+7
-1
lib/pls/include/pls/dataflow/dataflow.h
+4
-0
lib/pls/include/pls/dataflow/graph.h
+15
-0
lib/pls/include/pls/dataflow/internal/input.h
+23
-13
lib/pls/include/pls/dataflow/internal/inputs.h
+33
-2
lib/pls/include/pls/dataflow/internal/output.h
+7
-3
lib/pls/include/pls/dataflow/internal/outputs.h
+1
-1
lib/pls/include/pls/dataflow/internal/token.h
+4
-0
No files found.
app/playground/main.cpp
View file @
f374d93f
...
@@ -5,9 +5,15 @@
...
@@ -5,9 +5,15 @@
#include <pls/pls.h>
#include <pls/pls.h>
#include <pls/dataflow/graph.h>
#include <pls/dataflow/graph.h>
#include <pls/dataflow/internal/token.h>
int
main
()
{
int
main
()
{
using
namespace
pls
::
dataflow
;
using
namespace
pls
::
dataflow
;
graph
<
inputs
<
int
>
,
outputs
<
int
,
int
>
,
8
>
graph
;
graph
<
inputs
<
int
,
int
>
,
outputs
<
int
,
int
>
,
8
>
graph
;
graph
.
output
<
0
>
().
connect
(
graph
.
input
<
0
>
());
graph
.
output
<
1
>
().
connect
(
graph
.
input
<
1
>
());
graph
.
input
<
0
>
().
push_token
(
pls
::
dataflow
::
internal
::
token
<
int
>
());
graph
.
input
<
1
>
().
push_token
(
pls
::
dataflow
::
internal
::
token
<
int
>
());
}
}
lib/pls/include/pls/dataflow/dataflow.h
View file @
f374d93f
...
@@ -2,4 +2,8 @@
...
@@ -2,4 +2,8 @@
#ifndef PLS_DATAFLOW_DATAFLOW_H_
#ifndef PLS_DATAFLOW_DATAFLOW_H_
#define PLS_DATAFLOW_DATAFLOW_H_
#define PLS_DATAFLOW_DATAFLOW_H_
#include "graph.h"
#include "inputs.h"
#include "outputs.h"
#endif //PLS_DATAFLOW_DATAFLOW_H_
#endif //PLS_DATAFLOW_DATAFLOW_H_
lib/pls/include/pls/dataflow/graph.h
View file @
f374d93f
...
@@ -12,7 +12,22 @@ template<typename I, typename O, int P>
...
@@ -12,7 +12,22 @@ template<typename I, typename O, int P>
class
graph
{
class
graph
{
using
internal_inputs
=
typename
I
::
template
internal_inputs
<
P
>
;
using
internal_inputs
=
typename
I
::
template
internal_inputs
<
P
>
;
using
internal_outputs
=
typename
O
::
template
internal_outputs
<
P
>
;
using
internal_outputs
=
typename
O
::
template
internal_outputs
<
P
>
;
public
:
internal_inputs
inputs_
;
internal_outputs
outputs_
;
template
<
int
N
>
decltype
(
outputs_
.
template
get
<
N
>
())
output
()
{
return
outputs_
.
template
get
<
N
>
();
}
template
<
int
N
>
decltype
(
inputs_
.
template
get
<
N
>
())
input
()
{
return
inputs_
.
template
get
<
N
>
();
}
};
};
}
}
}
}
...
...
lib/pls/include/pls/dataflow/internal/input.h
View file @
f374d93f
...
@@ -2,23 +2,32 @@
...
@@ -2,23 +2,32 @@
#ifndef PLS_DATAFLOW_INTERNAL_INPUT_H_
#ifndef PLS_DATAFLOW_INTERNAL_INPUT_H_
#define PLS_DATAFLOW_INTERNAL_INPUT_H_
#define PLS_DATAFLOW_INTERNAL_INPUT_H_
#include
"token.h"
#include
<array>
#include "pls/internal/base/error_handling.h"
#include "pls/internal/base/error_handling.h"
#include "token.h"
namespace
pls
{
namespace
pls
{
namespace
dataflow
{
namespace
dataflow
{
namespace
internal
{
namespace
internal
{
template
<
typename
T
>
class
push_token_cb
{
public
:
virtual
void
token_pushed
(
int
pos
,
token_color
color
)
=
0
;
};
template
<
int
P
,
typename
T
>
class
input
{
class
input
{
template
<
typename
OT
>
template
<
int
OP
,
typename
OT
>
friend
friend
class
output
;
class
output
;
token
<
T
>
token_
;
std
::
array
<
token
<
T
>
,
P
>
tokens_
;
bool
filled_
;
bool
connected_
{
false
};
bool
connected_
;
push_token_cb
*
cb_
{
nullptr
};
int
input_pos_
{
0
};
void
connect
()
{
void
connect
()
{
if
(
connected_
)
{
if
(
connected_
)
{
...
@@ -27,15 +36,16 @@ class input {
...
@@ -27,15 +36,16 @@ class input {
connected_
=
true
;
connected_
=
true
;
}
}
input
()
:
filled_
{
false
},
connected_
{
false
}
{};
bool
has_token
(
token_color
color
)
const
{
return
filled_
&&
token_
.
color
()
==
color
;
}
const
token
<
T
>
&
get_token
()
const
{
return
token_
;
}
public
:
public
:
void
push_token
(
token
<
T
>
token
)
{
tokens_
[
token
.
color
().
get_index
(
P
)]
=
token
;
cb_
->
token_pushed
(
input_pos_
,
token
.
color
());
}
void
set_cb
(
push_token_cb
*
cb
,
int
input_pos
)
{
cb_
=
cb
;
input_pos_
=
input_pos
;
}
};
};
}
}
...
...
lib/pls/include/pls/dataflow/internal/inputs.h
View file @
f374d93f
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
#define PLS_DATAFLOW_INTERNAL_INPUTS_H_
#define PLS_DATAFLOW_INTERNAL_INPUTS_H_
#include <tuple>
#include <tuple>
#include <array>
#include "input.h"
#include "input.h"
...
@@ -11,15 +12,45 @@ namespace dataflow {
...
@@ -11,15 +12,45 @@ namespace dataflow {
namespace
internal
{
namespace
internal
{
template
<
int
P
,
typename
...
I
>
template
<
int
P
,
typename
...
I
>
class
inputs
{
class
inputs
:
push_token_cb
{
using
values_type
=
std
::
tuple
<
input
<
I
>
...
>
;
using
values_type
=
std
::
tuple
<
input
<
P
,
I
>
...
>
;
values_type
values_
;
values_type
values_
;
static
constexpr
unsigned
int
num_values
=
std
::
tuple_size
<
values_type
>::
value
;
std
::
array
<
std
::
atomic
<
unsigned
int
>
,
P
>
required_inputs_
;
public
:
public
:
inputs
()
{
for
(
int
i
=
0
;
i
<
P
;
i
++
)
{
required_inputs_
[
i
]
=
num_values
;
}
init_cb
<
0
,
I
...
>::
call
(
this
);
}
void
token_pushed
(
int
/*pos*/
,
token_color
color
)
override
{
int
current_required
=
--
required_inputs_
[
color
.
get_index
(
P
)];
if
(
current_required
==
0
)
{
std
::
cout
<<
"All Inputs Avaliable"
<<
std
::
endl
;
// TODO: Add proper callback in here
}
}
template
<
int
N
>
template
<
int
N
>
typename
std
::
tuple_element
<
N
,
values_type
>::
type
&
get
()
{
typename
std
::
tuple_element
<
N
,
values_type
>::
type
&
get
()
{
return
std
::
get
<
N
>
(
values_
);
return
std
::
get
<
N
>
(
values_
);
}
}
// TODO: Change CB code using proper templating to save method calls during execution...
template
<
int
POS
,
typename
...
TAIL
>
struct
init_cb
{
static
void
call
(
inputs
<
P
,
I
...
>
*
inputs
)
{
}
};
template
<
int
POS
,
typename
HEAD
,
typename
...
TAIL
>
struct
init_cb
<
POS
,
HEAD
,
TAIL
...
>
{
static
void
call
(
inputs
<
P
,
I
...
>
*
inputs
)
{
inputs
->
get
<
POS
>
().
set_cb
(
inputs
,
POS
);
init_cb
<
POS
+
1
,
TAIL
...
>::
call
(
inputs
);
}
};
};
};
}
}
...
...
lib/pls/include/pls/dataflow/internal/output.h
View file @
f374d93f
...
@@ -11,15 +11,15 @@ namespace pls {
...
@@ -11,15 +11,15 @@ namespace pls {
namespace
dataflow
{
namespace
dataflow
{
namespace
internal
{
namespace
internal
{
template
<
typename
T
>
template
<
int
P
,
typename
T
>
class
output
{
class
output
{
input
<
T
>
*
target_
;
input
<
P
,
T
>
*
target_
;
bool
connected_
;
bool
connected_
;
public
:
public
:
output
()
:
target_
{
nullptr
},
connected_
{
false
}
{};
output
()
:
target_
{
nullptr
},
connected_
{
false
}
{};
void
connect
(
input
<
T
>
&
target
)
{
void
connect
(
input
<
P
,
T
>
&
target
)
{
if
(
connected_
)
{
if
(
connected_
)
{
PLS_ERROR
(
"Must only connect output once. Please disconnect it before reconnecting."
)
PLS_ERROR
(
"Must only connect output once. Please disconnect it before reconnecting."
)
}
}
...
@@ -28,6 +28,10 @@ class output {
...
@@ -28,6 +28,10 @@ class output {
target_
=
&
target
;
target_
=
&
target
;
connected_
=
true
;
connected_
=
true
;
}
}
void
push_token
(
token
<
T
>
token
)
{
target_
->
push_token
(
token
);
}
};
};
}
}
...
...
lib/pls/include/pls/dataflow/internal/outputs.h
View file @
f374d93f
...
@@ -12,7 +12,7 @@ namespace internal {
...
@@ -12,7 +12,7 @@ namespace internal {
template
<
int
P
,
typename
...
O
>
template
<
int
P
,
typename
...
O
>
class
outputs
{
class
outputs
{
using
values_type
=
std
::
tuple
<
output
<
O
>
...
>
;
using
values_type
=
std
::
tuple
<
output
<
P
,
O
>
...
>
;
values_type
values_
;
values_type
values_
;
public
:
public
:
...
...
lib/pls/include/pls/dataflow/internal/token.h
View file @
f374d93f
...
@@ -13,6 +13,10 @@ namespace internal {
...
@@ -13,6 +13,10 @@ namespace internal {
*/
*/
struct
token_color
{
struct
token_color
{
unsigned
int
clock_
;
unsigned
int
clock_
;
int
get_index
(
int
parallel_limit
)
const
{
return
clock_
%
parallel_limit
;
}
};
};
template
<
typename
T
>
template
<
typename
T
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment