Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[runtime][variables] Work on the variables infrastructure: space to r…
…egister variable, scheduler to register event, and the different accesses to variables (read, write, readwrite.
- Loading branch information
Showing
22 changed files
with
822 additions
and
311 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,29 @@ | |||
// Copyright 2018 Pierre Talbot (IRCAM) | |||
|
|||
// Licensed under the Apache License, Version 2.0 (the "License"); | |||
// you may not use this file except in compliance with the License. | |||
// You may obtain a copy of the License at | |||
|
|||
// http://www.apache.org/licenses/LICENSE-2.0 | |||
|
|||
// Unless required by applicable law or agreed to in writing, software | |||
// distributed under the License is distributed on an "AS IS" BASIS, | |||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
// See the License for the specific language governing permissions and | |||
// limitations under the License. | |||
|
|||
#[error(E0033, 1, 0)] | |||
|
|||
package test; | |||
|
|||
public class E0033_10 | |||
{ | |||
public proc test() = | |||
single_time LMax x = new LMax(0); | |||
par | |||
// The result of x |= 3 depends on `f(readwrite x)`, but it can only be scheduled after `g(write x)` | |||
|| f(readwrite x) | |||
|| when x |= 3 then g(write x) end | |||
end | |||
end | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
runtime/src/main/java/bonsai/runtime/synchronous/Environment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,81 @@ | |||
// Copyright 2016 Pierre Talbot (IRCAM) | |||
|
|||
// Licensed under the Apache License, Version 2.0 (the "License"); | |||
// you may not use this file except in compliance with the License. | |||
// You may obtain a copy of the License at | |||
|
|||
// http://www.apache.org/licenses/LICENSE-2.0 | |||
|
|||
// Unless required by applicable law or agreed to in writing, software | |||
// distributed under the License is distributed on an "AS IS" BASIS, | |||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
// See the License for the specific language governing permissions and | |||
// limitations under the License. | |||
|
|||
package bonsai.runtime.synchronous; | |||
|
|||
import java.util.*; | |||
import java.util.function.*; | |||
import bonsai.runtime.core.*; | |||
import bonsai.runtime.synchronous.variables.*; | |||
import bonsai.runtime.synchronous.interfaces.*; | |||
import bonsai.runtime.synchronous.statements.SpaceStmt; | |||
|
|||
public class Environment<Queue extends Queueing<Future>> | |||
{ | |||
private Space space; | |||
private Queue queue; | |||
private Scheduler scheduler; | |||
|
|||
public Environment(Queue queue) | |||
{ | |||
this.queue = queue; | |||
space = new Space(); | |||
scheduler = new Scheduler(); | |||
} | |||
|
|||
/// We create and push the branches created in the current instant onto the queue. | |||
/// It corresponds to `push: Store(L3) -> L4` in the lattice hierarchy. | |||
/// Caution: this function must always be called even with an empty set of branches. | |||
/// Rational: this function marks the end of an instant, and therefore internal data might be reinitialized. | |||
/// @see Future | |||
public void pushBranches(/* ArrayList<SpaceStmt> branches */) { | |||
// ArrayList<Future> futures = Future.createFutures(branches, varsST, varsWL); | |||
// queue.push(futures); | |||
} | |||
|
|||
public Optional<Future> pop() { | |||
// if(!queue.isEmpty()) { | |||
// Future future = queue.pop(); | |||
// future.restoreWL(varsWL); | |||
// return Optional.of(future); | |||
// } | |||
// else { | |||
return Optional.empty(); | |||
// } | |||
} | |||
|
|||
public boolean isEmpty() { | |||
return queue.isEmpty(); | |||
} | |||
|
|||
public int queueSize() { | |||
return queue.size(); | |||
} | |||
|
|||
// private HashMap<String, Variable> vars() { | |||
// return vars; | |||
// } | |||
|
|||
public Variable lookUpVar(String name) { | |||
return space.lookUpVar(name); | |||
} | |||
|
|||
public void subscribe(Event event, Schedulable program) { | |||
scheduler.subscribe(event, program); | |||
} | |||
|
|||
public void schedule(Event event) { | |||
scheduler.schedule(event); | |||
} | |||
} |
57 changes: 57 additions & 0 deletions
57
runtime/src/main/java/bonsai/runtime/synchronous/Event.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,57 @@ | |||
// Copyright 2018 Pierre Talbot | |||
|
|||
// Licensed under the Apache License, Version 2.0 (the "License"); | |||
// you may not use this file except in compliance with the License. | |||
// You may obtain a copy of the License at | |||
|
|||
// http://www.apache.org/licenses/LICENSE-2.0 | |||
|
|||
// Unless required by applicable law or agreed to in writing, software | |||
// distributed under the License is distributed on an "AS IS" BASIS, | |||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
// See the License for the specific language governing permissions and | |||
// limitations under the License. | |||
|
|||
package bonsai.runtime.synchronous; | |||
|
|||
import bonsai.runtime.synchronous.variables.Variable; | |||
|
|||
enum EventKind { | |||
CAN_READ, | |||
CAN_READWRITE | |||
} | |||
|
|||
public class Event { | |||
private EventKind kind; | |||
private Integer uid; | |||
|
|||
public Event(EventKind kind, Integer uid) { | |||
this.kind = kind; | |||
this.uid = uid; | |||
} | |||
|
|||
public static Event makeCanRead(Variable var) { | |||
return new Event(EventKind.CAN_READ, var.uid()); | |||
} | |||
|
|||
public static Event makeCanReadWrite(Variable var) { | |||
return new Event(EventKind.CAN_READWRITE, var.uid()); | |||
} | |||
|
|||
public int hashCode() { | |||
return uid + ((kind == EventKind.CAN_READ) ? 0: 1000000); | |||
} | |||
|
|||
public boolean equals(Object obj) { | |||
if (obj == null) { | |||
return false; | |||
} | |||
else if (getClass() != obj.getClass()) { | |||
return false; | |||
} | |||
else { | |||
Event e = (Event) obj; | |||
return kind == e.kind && uid == e.uid; | |||
} | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
runtime/src/main/java/bonsai/runtime/synchronous/Scheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,44 @@ | |||
// Copyright 2018 Pierre Talbot | |||
|
|||
// Licensed under the Apache License, Version 2.0 (the "License"); | |||
// you may not use this file except in compliance with the License. | |||
// You may obtain a copy of the License at | |||
|
|||
// http://www.apache.org/licenses/LICENSE-2.0 | |||
|
|||
// Unless required by applicable law or agreed to in writing, software | |||
// distributed under the License is distributed on an "AS IS" BASIS, | |||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
// See the License for the specific language governing permissions and | |||
// limitations under the License. | |||
|
|||
package bonsai.runtime.synchronous; | |||
|
|||
import java.util.*; | |||
import java.util.function.*; | |||
import bonsai.runtime.core.*; | |||
import bonsai.runtime.synchronous.variables.*; | |||
import bonsai.runtime.synchronous.interfaces.*; | |||
|
|||
public class Scheduler | |||
{ | |||
private HashMap<Event, ArrayList<Schedulable>> waitingQueue; | |||
|
|||
public Scheduler() { | |||
waitingQueue = new HashMap(); | |||
} | |||
|
|||
public void subscribe(Event event, Schedulable program) { | |||
waitingQueue | |||
.computeIfAbsent(event, k -> new ArrayList<>()) | |||
.add(program); | |||
} | |||
|
|||
public void schedule(Event event) { | |||
ArrayList<Schedulable> programs = waitingQueue.get(event); | |||
for (Schedulable s: programs) { | |||
s.schedule(null); | |||
} | |||
programs.clear(); | |||
} | |||
} |
Oops, something went wrong.